[@testing-library/react 오류] Property 'toBeInTheDocument' does not exist on type 'Matchers<void, HTMLElement> …

허지예·2024년 8월 11일
0

개인 프로젝트 기록

목록 보기
10/17
expect(element).toBeInTheDocument();

이렇게 사용했을 때 다음과 같은 오류가 발생했다.

Property 'toBeInTheDocument' does not exist on type 'Matchers<void, HTMLElement> & SnapshotMatchers<void, HTMLElement> & Inverse<JestMatchers<void, HTMLElement>> & PromiseMatchers<...>'.

해결 방법

  1. jest.setup.ts 작성

    import '@testing-library/jest-dom/jest-globals';
  1. jest.config.js 수정

    /** @type {import('ts-jest').JestConfigWithTsJest} **/
    module.exports = {
      ...,
      setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
    };

+) 관련 다운로드한 패키지

  • jest
  • @testing-library/dom
  • @testing-library/jest-dom
  • @testing-library/react
  • @types/jest
  • @types/react
  • @types/react-dom
profile
대학생에서 취준생으로 진화했다가 지금은 풀스택 개발자로 2차 진화함

0개의 댓글

관련 채용 정보