For some React component testing, we have common setup in each test file:
import { render } from 'react-testing-library'
import 'jest-dom/extend-expect'
import 'react-testing-library/cleanup-after-each'
We want to setup a common place for JEST to load those scripts:
// jest.config.js module.exports = {
setupTestFrameworkScriptFile: '<rootDir>/testSetup.js'
}
// testSetup.js import 'jest-dom/extend-expect'
import 'react-testing-library/cleanup-after-each'
Then for component test file, we can remove those two lines.