Skip to content

Commit 1d6d9bd

Browse files
committed
Switch to Jest
1 parent d103e3e commit 1d6d9bd

File tree

9 files changed

+3969
-2840
lines changed

9 files changed

+3969
-2840
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ node_js:
33
- "8"
44
script:
55
- npm run lint
6-
- npm run test:cov
6+
- npm test
77
after_success:
88
- npm run coverage

package-lock.json

Lines changed: 3816 additions & 2667 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
"clean": "rimraf lib dist es coverage",
1414
"lint": "eslint src test",
1515
"prepare": "npm run clean && npm run build",
16-
"test": "cross-env BABEL_ENV=test NODE_ENV=test mocha --recursive --require babel-register --require ./test/setup.js",
17-
"test:watch": "npm test -- --watch",
18-
"test:cov": "cross-env NODE_ENV=test nyc npm test",
19-
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
16+
"test": "jest",
17+
"coverage": "codecov"
2018
},
2119
"repository": {
2220
"type": "git",
@@ -51,19 +49,19 @@
5149
},
5250
"dependencies": {
5351
"hoist-non-react-statics": "^2.5.0",
54-
"invariant": "^2.0.0",
52+
"invariant": "^2.2.4",
5553
"lodash": "^4.17.5",
5654
"lodash-es": "^4.17.5",
5755
"loose-envify": "^1.1.0",
58-
"prop-types": "^15.6.0"
56+
"prop-types": "^15.6.1"
5957
},
6058
"devDependencies": {
6159
"babel-cli": "^6.26.0",
6260
"babel-core": "^6.26.0",
63-
"babel-eslint": "^8.2.1",
61+
"babel-eslint": "^8.2.2",
6462
"babel-plugin-check-es2015-constants": "^6.3.13",
6563
"babel-plugin-external-helpers": "^6.22.0",
66-
"babel-plugin-istanbul": "^4.1.5",
64+
"babel-plugin-istanbul": "^4.1.6",
6765
"babel-plugin-syntax-jsx": "^6.3.13",
6866
"babel-plugin-transform-decorators-legacy": "^1.2.0",
6967
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
@@ -86,28 +84,23 @@
8684
"babel-plugin-transform-object-rest-spread": "^6.26.0",
8785
"babel-plugin-transform-react-display-name": "^6.4.0",
8886
"babel-plugin-transform-react-jsx": "^6.4.0",
89-
"babel-register": "^6.26.0",
9087
"codecov": "^3.0.0",
9188
"create-react-class": "^15.6.3",
92-
"cross-env": "^5.1.3",
89+
"cross-env": "^5.1.4",
9390
"es3ify": "^0.2.0",
94-
"eslint": "^4.17.0",
95-
"eslint-plugin-import": "^2.8.0",
96-
"eslint-plugin-react": "^7.6.1",
97-
"expect": "^1.20.2",
91+
"eslint": "^4.19.1",
92+
"eslint-plugin-import": "^2.10.0",
93+
"eslint-plugin-react": "^7.7.0",
9894
"glob": "^7.1.1",
99-
"istanbul": "^0.4.4",
100-
"jsdom": "^11.6.2",
101-
"mocha": "^5.0.1",
102-
"nyc": "^11.5.0",
95+
"jest": "^22.4.3",
10396
"react": "^15.6.2",
10497
"react-dom": "^15.6.2",
10598
"redux": "^3.0.0",
10699
"rimraf": "^2.6.2",
107-
"rollup": "^0.56.1",
100+
"rollup": "^0.56.5",
108101
"rollup-plugin-babel": "^3.0.3",
109-
"rollup-plugin-commonjs": "^8.3.0",
110-
"rollup-plugin-node-resolve": "^3.0.3",
102+
"rollup-plugin-commonjs": "^8.4.1",
103+
"rollup-plugin-node-resolve": "^3.3.0",
111104
"rollup-plugin-replace": "^2.0.0",
112105
"rollup-plugin-uglify": "^3.0.0"
113106
},
@@ -116,15 +109,8 @@
116109
"loose-envify"
117110
]
118111
},
119-
"nyc": {
120-
"require": [
121-
"babel-register"
122-
],
123-
"all": "true",
124-
"sourceMap": false,
125-
"instrument": false,
126-
"include": [
127-
"src/**/*.js"
128-
]
112+
"jest": {
113+
"coverageDirectory": "./coverage/",
114+
"collectCoverage": true
129115
}
130116
}

test/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"jest": true
4+
}
5+
}

test/components/Provider.spec.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*eslint-disable react/prop-types*/
22

3-
import expect from 'expect'
43
import React, { Component } from 'react'
54
import PropTypes from 'prop-types'
65
import TestUtils from 'react-dom/test-utils'
@@ -36,7 +35,7 @@ describe('React', () => {
3635
<Provider store={store}>
3736
<div />
3837
</Provider>
39-
)).toNotThrow()
38+
)).not.toThrow()
4039

4140
expect(() => TestUtils.renderIntoDocument(
4241
<Provider store={store}>
@@ -57,14 +56,14 @@ describe('React', () => {
5756
it('should add the store to the child context', () => {
5857
const store = createStore(() => ({}))
5958

60-
const spy = expect.spyOn(console, 'error')
59+
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
6160
const tree = TestUtils.renderIntoDocument(
6261
<Provider store={store}>
6362
<Child />
6463
</Provider>
6564
)
66-
spy.destroy()
67-
expect(spy.calls.length).toBe(0)
65+
spy.mockRestore()
66+
expect(spy).toHaveBeenCalledTimes(0)
6867

6968
const child = TestUtils.findRenderedComponentWithType(tree, Child)
7069
expect(child.context.store).toBe(store)
@@ -75,14 +74,14 @@ describe('React', () => {
7574
const CustomProvider = createProvider('customStoreKey');
7675
const CustomChild = createChild('customStoreKey');
7776

78-
const spy = expect.spyOn(console, 'error');
77+
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
7978
const tree = TestUtils.renderIntoDocument(
8079
<CustomProvider store={store}>
8180
<CustomChild />
8281
</CustomProvider>
8382
)
84-
spy.destroy()
85-
expect(spy.calls.length).toBe(0)
83+
spy.mockRestore()
84+
expect(spy).toHaveBeenCalledTimes(0)
8685

8786
const child = TestUtils.findRenderedComponentWithType(tree, CustomChild)
8887
expect(child.context.customStoreKey).toBe(store)
@@ -111,33 +110,33 @@ describe('React', () => {
111110
const child = TestUtils.findRenderedComponentWithType(container, Child)
112111
expect(child.context.store.getState()).toEqual(11)
113112

114-
let spy = expect.spyOn(console, 'error')
113+
let spy = jest.spyOn(console, 'error').mockImplementation(() => {})
115114
container.setState({ store: store2 })
116-
spy.destroy()
115+
spy.mockRestore()
117116

118117
expect(child.context.store.getState()).toEqual(11)
119-
expect(spy.calls.length).toBe(1)
120-
expect(spy.calls[0].arguments[0]).toBe(
118+
expect(spy).toHaveBeenCalledTimes(1)
119+
expect(spy.mock.calls[0][0]).toBe(
121120
'<Provider> does not support changing `store` on the fly. ' +
122121
'It is most likely that you see this error because you updated to ' +
123122
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
124123
'automatically. See https://github.com/reactjs/react-redux/releases/' +
125124
'tag/v2.0.0 for the migration instructions.'
126125
)
127126

128-
spy = expect.spyOn(console, 'error')
127+
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
129128
container.setState({ store: store3 })
130-
spy.destroy()
129+
spy.mockRestore()
131130

132131
expect(child.context.store.getState()).toEqual(11)
133-
expect(spy.calls.length).toBe(0)
132+
expect(spy).toHaveBeenCalledTimes(0)
134133
})
135134

136135
it('should handle subscriptions correctly when there is nested Providers', () => {
137136
const reducer = (state = 0, action) => (action.type === 'INC' ? state + 1 : state)
138137

139138
const innerStore = createStore(reducer)
140-
const innerMapStateToProps = expect.createSpy().andCall(state => ({ count: state }))
139+
const innerMapStateToProps = jest.fn(state => ({ count: state }))
141140
@connect(innerMapStateToProps)
142141
class Inner extends Component {
143142
render() { return <div>{this.props.count}</div> }
@@ -150,10 +149,10 @@ describe('React', () => {
150149
}
151150

152151
TestUtils.renderIntoDocument(<Provider store={outerStore}><Outer /></Provider>)
153-
expect(innerMapStateToProps.calls.length).toBe(1)
152+
expect(innerMapStateToProps).toHaveBeenCalledTimes(1)
154153

155154
innerStore.dispatch({ type: 'INC'})
156-
expect(innerMapStateToProps.calls.length).toBe(2)
155+
expect(innerMapStateToProps).toHaveBeenCalledTimes(2)
157156
})
158157
})
159158

0 commit comments

Comments
 (0)