인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

형욱박님의 프로필 이미지
형욱박

작성한 질문수

따라하며 배우는 도커와 CI환경 [2023.11 업데이트]

리액트 앱 테스트 하기

테스트 실행 시 fail이 발생하는데 왜 그런걸까요??ㅜㅜ

작성

·

1.4K

0

안녕하세요. 테스트 진행 중에 fail이 발생해서 왜 그런지 잘 모르겠습니다. 

아래는 fail 로그예요

 FAIL  src/App.test.js

  ✕ renders learn react link (42ms)

  ● renders learn react link

    Unable to find an element with the text: /learn react/i. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

    <body>

      <div>

        <div

          class="App"

        >

          <header

            class="App-header"

          >

            <img

              alt="logo"

              class="App-logo"

              src="logo.svg"

            />

            <p>

              Edit 

              <code>

                src/App.js

              </code>

               and save to reload.

            </p>

            <a

              class="App-link"

              href="https://reactjs.org"

              rel="noopener noreferrer"

              target="_blank"

            >

              반갑습니다.

            </a>

          </header>

        </div>

      </div>

    </body>

       5 | test('renders learn react link', () => {

       6 |   const { getByText } = render(<App />);

    >  7 |   const linkElement = getByText(/learn react/i);

         |                       ^

       8 |   expect(linkElement).toBeInTheDocument();

       9 | });

      10 | 

      at Object.getElementError (node_modules/@testing-library/dom/dist/config.js:34:12)

      at node_modules/@testing-library/dom/dist/query-helpers.js:71:38

      at getByText (node_modules/@testing-library/dom/dist/query-helpers.js:54:17)

      at Object.<anonymous> (src/App.test.js:7:23)

Test Suites: 1 failed, 1 total

Tests:       1 failed, 1 total

Snapshots:   0 total

Time:        1.958s

Ran all test suites.

답변 1

0

John Ahn님의 프로필 이미지
John Ahn
지식공유자

왜냐면   learn react 라는 글짜가  렌더링 하는 jsx 안에 있어야 하는 데 없어서 그런겁니다 .  
저 테스트 부분을 없애고 진행해주세요 ^^ 

형욱박님의 프로필 이미지
형욱박

작성한 질문수

질문하기