Skip to content

Commit 17ed918

Browse files
committed
use enzyme in tests (resolves reduxjs#1481)
1 parent 952b45d commit 17ed918

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

examples/counter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Redux counter example",
55
"scripts": {
66
"start": "node server.js",
7-
"test": "cross-env NODE_ENV=test mocha --recursive --compilers js:babel-register --require ./test/setup.js",
7+
"test": "cross-env NODE_ENV=test mocha --recursive --compilers js:babel-register",
88
"test:watch": "npm test -- --watch"
99
},
1010
"repository": {
@@ -30,9 +30,9 @@
3030
"babel-preset-react-hmre": "^1.0.1",
3131
"babel-register": "^6.3.13",
3232
"cross-env": "^1.0.7",
33+
"enzyme": "^2.0.0",
3334
"expect": "^1.6.0",
3435
"express": "^4.13.3",
35-
"jsdom": "^5.6.1",
3636
"mocha": "^2.2.5",
3737
"node-libs-browser": "^0.5.2",
3838
"react-addons-test-utils": "^0.14.7",

examples/counter/test/components/Counter.spec.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,64 @@
11
import expect from 'expect'
22
import React from 'react'
3-
import TestUtils from 'react-addons-test-utils'
3+
import { shallow } from 'enzyme'
44
import Counter from '../../components/Counter'
55

66
function setup(value = 0) {
77
const actions = {
88
onIncrement: expect.createSpy(),
99
onDecrement: expect.createSpy()
1010
}
11-
const component = TestUtils.renderIntoDocument(
11+
const component = shallow(
1212
<Counter value={value} {...actions} />
1313
)
14+
1415
return {
1516
component: component,
1617
actions: actions,
17-
buttons: TestUtils.scryRenderedDOMComponentsWithTag(component, 'button'),
18-
p: TestUtils.findRenderedDOMComponentWithTag(component, 'p')
18+
buttons: component.find('button'),
19+
p: component.find('p')
1920
}
2021
}
2122

2223
describe('Counter component', () => {
2324
it('should display count', () => {
2425
const { p } = setup()
25-
expect(p.textContent).toMatch(/^Clicked: 0 times/)
26+
expect(p.text()).toMatch(/^Clicked: 0 times/)
2627
})
2728

2829
it('first button should call onIncrement', () => {
2930
const { buttons, actions } = setup()
30-
TestUtils.Simulate.click(buttons[0])
31+
buttons.at(0).simulate('click')
3132
expect(actions.onIncrement).toHaveBeenCalled()
3233
})
3334

3435
it('second button should call onDecrement', () => {
3536
const { buttons, actions } = setup()
36-
TestUtils.Simulate.click(buttons[1])
37+
buttons.at(1).simulate('click')
3738
expect(actions.onDecrement).toHaveBeenCalled()
3839
})
3940

4041
it('third button should not call onIncrement if the counter is even', () => {
4142
const { buttons, actions } = setup(42)
42-
TestUtils.Simulate.click(buttons[2])
43+
buttons.at(2).simulate('click')
4344
expect(actions.onIncrement).toNotHaveBeenCalled()
4445
})
4546

4647
it('third button should call onIncrement if the counter is odd', () => {
4748
const { buttons, actions } = setup(43)
48-
TestUtils.Simulate.click(buttons[2])
49+
buttons.at(2).simulate('click')
4950
expect(actions.onIncrement).toHaveBeenCalled()
5051
})
5152

5253
it('third button should call onIncrement if the counter is odd and negative', () => {
5354
const { buttons, actions } = setup(-43)
54-
TestUtils.Simulate.click(buttons[2])
55+
buttons.at(2).simulate('click')
5556
expect(actions.onIncrement).toHaveBeenCalled()
5657
})
5758

5859
it('fourth button should call onIncrement in a second', (done) => {
5960
const { buttons, actions } = setup()
60-
TestUtils.Simulate.click(buttons[3])
61+
buttons.at(3).simulate('click')
6162
setTimeout(() => {
6263
expect(actions.onIncrement).toHaveBeenCalled()
6364
done()

examples/counter/test/setup.js

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

0 commit comments

Comments
 (0)