모든 일에 의문을 제기하고 그 의문을 해결하기 위해 지식을 구하고 공부
CRA하지 않은 앱에서 test config 설정하는 법! 본문
CRA(create-react-app)으로 앱을 만든 경우, setupTests.js 파일이 test 설정 관련 파일로 설정되어 있다.
CRA로 앱을 만들지 않은 경우, 어떻게 config를 조정할까?!
react-testing-library 공식 홈페이지에서는 react-testing-library 설정을 jest.config.js 로 하는 법을 알려주고 있다.
testing-library.com/docs/react-testing-library/setup
Setup | Testing Library
React Testing Library does not require any configuration to be used. However,
testing-library.com
즉, jest 설정하는 법을 보면 된다!!
Configuring Jest · Jest
Jest's configuration can be defined in the package.json file of your project, or through a jest.config.js, or jest.config.ts file or through the --config option. If you'd like to use your package.json to store Jest's config, the "jest" key should be used o
jestjs.io
- 최상위 루트에 jest.config.js 파일을 생성
- 원하는 곳에 setupTests.js 파일을 생성한 후..
jest.config.js에서 setup파일 경로를 setupTests.js가 있는 경로로 지정해주면 된다.
// jest.config.js
module.exports = {
setupFilesAfterEnv: ["./pathToYour/setupTests.js"]
};
위의 jest 공식홈페이지를 보면.. setupFilesAfterEnv 외에 다양한 설정 키가 나열되어 있다.
'테스팅 라이브러리 > React-Testing-Library' 카테고리의 다른 글
에러 | ReferenceError: regeneratorRuntime is not defined (0) | 2021.03.13 |
---|---|
r-t-l는 describe, it을 쓰는가? test를 쓰는가? (0) | 2021.03.13 |
RTL Varient, Queries 종류 + jest Matcher (0) | 2021.02.23 |
TDD의 장점/핵심 과정/RTL의 장점 (0) | 2021.02.23 |
React Testing Library 설치 및 설정 (0) | 2021.01.24 |