Вот package.json
моего проекта, в котором используется шутка. У меня есть папки src
и test
на одном уровне. В отличие от вас, я использую массив setupFiles
в jest
объекте package.json
.
{
"name": "app",
"version": "1.0.0",
"description": "App",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --colors --mode=development",
"build": "webpack --mode=production",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"jest": {
"setupFiles": [
"./test/jestsetup.js"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"moduleNameMapper": {
"\\.(css|less)$": "identity-obj-proxy"
}
},
"keywords": [
"react"
],
"license": "MIT",
"devDependencies": {
"babel-jest": "^23.2.0",
"babel-loader": "^7.1.3",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"css-loader": "^0.28.11",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.4",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.2.0",
"react-test-renderer": "^16.4.1",
"style-loader": "^0.21.0",
"webpack": "^4.6.0",
"webpack-cli": "^2.0.15",
"webpack-dev-server": "^3.1.3"
},
"dependencies": {
"react": "^16.3.2",
"react-dom": "^16.3.2"
}
}
Вот это jestsetup.js
import Enzyme, { shallow, render, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });