[Jest] Set up Testing Globals in an Application with Jest

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.

上一篇:【算法学习】LCP 01. 猜数字(java / c / c++ / python / go / rust)


下一篇:Selenium+Java元素定位之三