expect(element).toBeInTheDocument();
이렇게 사용했을 때 다음과 같은 오류가 발생했다.
Property 'toBeInTheDocument' does not exist on type 'Matchers<void, HTMLElement> & SnapshotMatchers<void, HTMLElement> & Inverse<JestMatchers<void, HTMLElement>> & PromiseMatchers<...>'.
jest.setup.ts 작성
import '@testing-library/jest-dom/jest-globals';
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