Skip to content

Commit 0bf67c6

Browse files
author
Rishabh Rao
committed
Setup Jest with Babel, React and Enzyme
1 parent ae7ebc5 commit 0bf67c6

File tree

5 files changed

+2373
-31
lines changed

5 files changed

+2373
-31
lines changed

.babelrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@
4242
"stage-1"
4343
]
4444
},
45+
"test": {
46+
"presets": [
47+
"es2015",
48+
"react",
49+
"stage-1"
50+
]
51+
}
4552
}
46-
}
53+
}

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
collectCoverage: true,
6+
coverageDirectory: "coverage",
7+
8+
setupFiles: [
9+
"./src/setupTests.js",
10+
],
11+
};

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"flow": "flow check src",
2222
"lint": "eslint 'src/**/*.js'",
2323
"prettier": "prettier --config .prettierrc --write \"src/**/*.js\"",
24-
"test": "echo \"Error: no test specified\" && exit 1"
24+
"test": "jest"
2525
},
2626
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
2727
"license": "MIT",
2828
"devDependencies": {
2929
"babel-cli": "^6.24.1",
3030
"babel-core": "^6.25.0",
3131
"babel-eslint": "^8.0.1",
32+
"babel-jest": "^23.4.2",
3233
"babel-loader": "^7.1.1",
3334
"babel-plugin-flow-react-proptypes": "^3.4.2",
3435
"babel-plugin-transform-react-remove-prop-types": "^0.4.6",
@@ -40,6 +41,8 @@
4041
"babel-preset-stage-1": "^6.24.1",
4142
"babel-runtime": "^6.23.0",
4243
"cross-env": "^5.0.1",
44+
"enzyme": "^3.5.0",
45+
"enzyme-adapter-react-16": "^1.3.0",
4346
"eslint": "^4.2.0",
4447
"eslint-config-fbjs": "^2.0.0",
4548
"eslint-plugin-babel": "^4.1.2",
@@ -49,8 +52,12 @@
4952
"eslint-plugin-react": "^7.4.0",
5053
"eslint-plugin-relay": "^0.0.19",
5154
"flow-bin": "^0.57.3",
55+
"jest": "^23.5.0",
5256
"prettier": "^1.7.4",
5357
"prop-types": "^15.5.10",
58+
"react": "^16.4.2",
59+
"react-dom": "^16.4.2",
60+
"react-test-renderer": "^16.4.2",
5461
"rimraf": "^2.6.1",
5562
"webpack": "^3.3.0"
5663
},

src/setupTests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Enzyme from 'enzyme';
2+
import Adapter from 'enzyme-adapter-react-16';
3+
4+
Enzyme.configure({adapter: new Adapter()});

0 commit comments

Comments
 (0)