react config test env with jest and create-react-app 1

c3tc3tc3t發表於2018-10-29

/.babelrc

1 {
2   "presets": ["@babel/preset-env","@babel/preset-react"],
3   "plugins":[
4     "@babel/plugin-proposal-class-properties"
5   ]
6 }

/jest.config.js

1 module.exports = {
2 
3 
4   "setupFiles": ["./tests/setup.js"],
5 
6   testEnvironment: "node",
7 
8   
9 };

/package.json

 1   "devDependencies": {
 2     "babel-core": "7.0.0-bridge.0",
 3     "@babel/core": "^7.1.2",
 4     "@babel/preset-env": "^7.1.0",
 5     "@babel/preset-react": "^7.0.0",
 6     "@babel/plugin-proposal-class-properties": "^7.1.0",
 7     "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
 8     "babel-jest": "^23.6.0",
 9     "enzyme": "/home/rudy/.config/yarn/global/node_modules/enzyme",
10     "enzyme-adapter-react-16": "/home/rudy/.config/yarn/global/node_modules/enzyme-adapter-react-16",
11     "jest": "^23.6.0"
12   },
13   "scripts": {
14     "start": "react-scripts start",
15     "build": "react-scripts build",
16     "test": "jest",
17     "eject": "react-scripts eject"
18   },

/tests/setup.js

1 import { configure } from 'enzyme';
2 import Adapter from 'enzyme-adapter-react-16';
3 configure({ adapter: new Adapter() });

 

相關文章