Configuration Unit Test with Jest - gloriaJun/react-realworld-example-app GitHub Wiki
npm install -D jest react-testing-library
# or
yarn add -D jest react-testing-library
{
"scripts": {
"test": "jest --config jest.config.js",
"test:watch": "$npm_execpath test --watch",
"test:coverage": "$npm_execpath test --coverage --colors"
}
}
jest.config.js
module.exports = {
// Automatically clear mock calls and instances between every test
clearMocks: true,
setupFiles: ['<rootDir>/tests/unit/testSetup.js'],
setupFilesAfterEnv: ['react-testing-library/cleanup-after-each'],
// collectCoverageFrom: ['src/**/*.{js,jsx}'],
// moduleDirectories: ['src', 'node_modules'],
moduleNameMapper: {
'^@(.*)$': '<rootDir>/src/$1',
// '^@components/(.*)$': '<rootDir>/src/components/$1',
// '^@store/(.*)$': '<rootDir>/src/store/$1',
},
moduleFileExtensions: ['js', 'jsx', 'json'],
};
env: {
// ...SKIP...
jest: true, // added
},
npm run test
# or
yarn test
npm run test:watch
# or
yarn test:watch
npm run test InputText
# or
npm run test tests/unit/components/InputText.test.js
# or
npm run test InputText.test.js