Skip to content

Commit 172dc16

Browse files
committed
Use Jest for testing
This commit uses Jest for testing everything instead of our homegrown combination of karma + mocha + expect. We were already using Jest to test react-router-redux and react-router-native, so this commit makes everything more consistent.
1 parent 3964114 commit 172dc16

28 files changed

+93
-468
lines changed

packages/react-router-config/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ es
22
node_modules
33
umd
44
/*.js
5-
!karma.conf.js
6-
!tests.webpack.js
75
!webpack.config.js

packages/react-router-config/karma.conf.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

packages/react-router-config/modules/__tests__/matchRoutes-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import matchRoutes from '../matchRoutes'
2-
import expect from 'expect'
32

43
it('finds matched routes', () => {
54
const routes = [

packages/react-router-config/modules/__tests__/renderRoutes-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('renderRoutes', () => {
2626
</StaticRouter>
2727
)
2828
expect(rendered.length).toEqual(1)
29-
expect(rendered[0]).toMatch(routeToMatch)
29+
expect(rendered[0]).toEqual(routeToMatch)
3030
})
3131

3232
describe('Switch usage', () => {
@@ -45,7 +45,7 @@ describe('renderRoutes', () => {
4545
</StaticRouter>
4646
)
4747
expect(rendered.length).toEqual(1)
48-
expect(rendered[0]).toMatch(routeToMatch)
48+
expect(rendered[0]).toEqual(routeToMatch)
4949
})
5050

5151
it('renders the first matched route in nested routes', () => {
@@ -70,8 +70,8 @@ describe('renderRoutes', () => {
7070
</StaticRouter>
7171
)
7272
expect(rendered.length).toEqual(2)
73-
expect(rendered[0]).toMatch(routeToMatch)
74-
expect(rendered[1]).toMatch(childRouteToMatch)
73+
expect(rendered[0]).toEqual(routeToMatch)
74+
expect(rendered[1]).toEqual(childRouteToMatch)
7575
})
7676
})
7777

packages/react-router-config/package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepublishOnly": "node ./tools/build.js",
2323
"clean": "git clean -fdX .",
2424
"lint": "eslint modules",
25-
"test": "karma start --single-run"
25+
"test": "jest"
2626
},
2727
"peerDependencies": {
2828
"react": "^15",
@@ -40,16 +40,8 @@
4040
"eslint": "^2.13.1",
4141
"eslint-plugin-import": "^1.15.0",
4242
"eslint-plugin-react": "^5.2.2",
43-
"expect": "^1.20.1",
4443
"gzip-size": "^3.0.0",
45-
"karma": "^0.13.22",
46-
"karma-browserstack-launcher": "^1.0.1",
47-
"karma-chrome-launcher": "^1.0.1",
48-
"karma-mocha": "^1.0.1",
49-
"karma-mocha-reporter": "^2.0.4",
50-
"karma-sourcemap-loader": "^0.3.7",
51-
"karma-webpack": "^1.7.0",
52-
"mocha": "^2.5.3",
44+
"jest": "^20.0.4",
5345
"pretty-bytes": "^3.0.1",
5446
"react": "^15.4.2",
5547
"react-addons-test-utils": "^15.4.2",

packages/react-router-config/tests.webpack.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/react-router-dom/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ es
22
node_modules
33
umd
44
/*.js
5-
!karma.conf.js
6-
!tests.webpack.js
75
!webpack.config.js

packages/react-router-dom/karma.conf.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

packages/react-router-dom/modules/__tests__/BrowserRouter-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import ReactDOM from 'react-dom'
43
import PropTypes from 'prop-types'
@@ -24,21 +23,22 @@ describe('A <BrowserRouter>', () => {
2423
</BrowserRouter>
2524
), node)
2625

27-
expect(history).toBeAn('object')
26+
expect(typeof history).toBe('object')
2827
})
2928

3029
it('warns when passed a history prop', () => {
3130
const history = {}
3231
const node = document.createElement('div')
33-
expect.spyOn(console, 'error')
32+
33+
spyOn(console, 'error')
3434

3535
ReactDOM.render((
3636
<BrowserRouter history={history} />
3737
), node)
3838

39-
expect(console.error.calls.length).toBe(1)
40-
expect(console.error.calls[0].arguments[0]).toMatch(
41-
/<BrowserRouter.*import \{ Router }/)
42-
expect.restoreSpies()
39+
expect(console.error.calls.count()).toBe(1)
40+
expect(console.error.calls.argsFor(0)[0]).toContain(
41+
'<BrowserRouter> ignores the history prop'
42+
)
4343
})
4444
})

packages/react-router-dom/modules/__tests__/HashRouter-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import expect from 'expect'
21
import React from 'react'
32
import ReactDOM from 'react-dom'
43
import PropTypes from 'prop-types'
@@ -24,21 +23,22 @@ describe('A <HashRouter>', () => {
2423
</HashRouter>
2524
), node)
2625

27-
expect(history).toBeAn('object')
26+
expect(typeof history).toBe('object')
2827
})
2928

3029
it('warns when passed a history prop', () => {
3130
const history = {}
3231
const node = document.createElement('div')
33-
expect.spyOn(console, 'error')
32+
33+
spyOn(console, 'error')
3434

3535
ReactDOM.render((
3636
<HashRouter history={history} />
3737
), node)
3838

39-
expect(console.error.calls.length).toBe(1)
40-
expect(console.error.calls[0].arguments[0]).toMatch(
41-
/<HashRouter.*import \{ Router }/)
42-
expect.restoreSpies()
39+
expect(console.error.calls.count()).toBe(1)
40+
expect(console.error.calls.argsFor(0)[0]).toContain(
41+
'<HashRouter> ignores the history prop'
42+
)
4343
})
4444
})

0 commit comments

Comments
 (0)