inflearn logo
강의

Course

Instructor

Learn React Testing by Following [Updated November 2023]

test 여러 개 실행 - fail 발생

290

FEZ

1 asked

0

안녕하세요. 강의 잘 듣고 있습니다. 강의 듣는 중 질문이 있어 질문남깁니다.

react-shop-test > src > pages > OrderPage > tests > calculate.test.js

파일을 그대로 복사하고 test.only 부분을 test로 바꾼 후 전체 테스트 돌렸습니다.

 

 ● total price of goods and options › total price starts with 0 and Updating total price when adding one product 
Expected element to have text content:
      1000
    Received:
      Total Price: 1500

total price starts with 0 and Updating total price when adding one product에서 위와 같이 금액이 맞지 않는 테스트 fail이 발생하는데 원인을 알 수 있을까요..? ( 나머지는 다 통과합니다. )

 test("total price starts with 0 and Updating total price when adding one product", async () => {
        render(<OrderPage />);

        const total = screen.getByText("Total Price:", {exact: false});
        expect(total).toHaveTextContent("0");

        const americaInput = await screen.findByRole("spinbutton", {
            name: "America",
        });
        userEvent.clear(americaInput);
        userEvent.type(americaInput, "1");

        expect(total).toHaveTextContent("1000");
    });

테스트코드는 이와 같습니다. america 하나를 했으니 1000원이 나와야 올바른 결과일 것 같은데 1500인 결과가 나와 fail 이 납니다. 나머지 테스트케이스에선 발생하지 않아 계산 로직이 잘못된 것 같진 않습니다.

test를 여러 개 한꺼번에 실행하면 안되는건가요?

뭔가 앞의 결과가 남아있어서 값의 오류가 발생하는 것 같아서요.

테스트를 할 때 .only를 붙여 하나씩만 실행해야 하는건가요..?

그렇다면 여러 개의 테스트를 동시에 실행하고 싶을 때는 어떻게 할 수 있을까요? 각 테스트를 파일 분리하여 작성해야 하나요?

웹앱 React-Context react jest

Answer 1

0

John Ahn

안녕하세요!!

테스트를 여러 개 한꺼번에 해도 1000원으로 결과가 나와야 합니다.
image
이런 식으로 요 ~

아마 코드 쪽에 오타가 있지 않나 싶습니다 ~

감사합니다.

제공해주신 코드를 vscode에서 켜도 eslint가 안됩니다.

0

278

2

ERROR

0

209

1

테스트 시간을 단축할 수 있는 방법에 대하여 문의드립니다.

0

360

1

useState 배열값 변경의 경우 테스트 멈춤

0

411

1

test was not wrapped in act관련 질문

0

290

2

안녕하세요! 로딩 상태 테스트에 관련된 질문입니다.

0

394

1

강의 관련 내용 github 업로드 질문

0

307

1

이미지가 안보인다 하셔서 다시 질문드립니다.

0

414

2

Test Fail이 발생합니다 ㅠㅠ

0

356

1

스타일 컴포넌트 테스트 방법

0

438

1

msw 에러

0

630

1

toHaveTextContent 에러

0

442

1

msw안돼는사람

0

579

1

This could be because the text is broken up by multiple elements. 에러

0

1716

2

Type.test.js파일에 궁금한점이 생겼습니다

0

351

1

28강 수강 중 JSX 작성 방법에 대해 궁금해져서 질문 남깁니다!

0

398

1

toHaveTextContent 에서 에러가 자꾸 나는데 아무리 찾아도 잘 모르겠습니다.

0

610

2

aria-*

0

438

1

This XML file does not appear to have any style information associated with it. The document tree is shown below. 에러

1

14082

1

컴포넌트 props내려줄때 코드는 어떻게 해야하나요

0

246

0

es6 jest 미지원 오류 문의

0

855

1

useMemo

0

280

1

axios 1.1.2 버전 issue ( SyntaxError: Cannot use import statement outside a module)

4

2222

5

2가지 질문사항입니다!

0

308

2