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 외에 다양한 설정 키가 나열되어 있다.