|
1 | 1 | import expect from 'expect'
|
2 | 2 | import React from 'react'
|
3 |
| -import TestUtils from 'react-addons-test-utils' |
| 3 | +import { shallow } from 'enzyme' |
4 | 4 | import Counter from '../../components/Counter'
|
5 | 5 |
|
6 | 6 | function setup(value = 0) {
|
7 | 7 | const actions = {
|
8 | 8 | onIncrement: expect.createSpy(),
|
9 | 9 | onDecrement: expect.createSpy()
|
10 | 10 | }
|
11 |
| - const component = TestUtils.renderIntoDocument( |
| 11 | + const component = shallow( |
12 | 12 | <Counter value={value} {...actions} />
|
13 | 13 | )
|
| 14 | + |
14 | 15 | return {
|
15 | 16 | component: component,
|
16 | 17 | actions: actions,
|
17 |
| - buttons: TestUtils.scryRenderedDOMComponentsWithTag(component, 'button'), |
18 |
| - p: TestUtils.findRenderedDOMComponentWithTag(component, 'p') |
| 18 | + buttons: component.find('button'), |
| 19 | + p: component.find('p') |
19 | 20 | }
|
20 | 21 | }
|
21 | 22 |
|
22 | 23 | describe('Counter component', () => {
|
23 | 24 | it('should display count', () => {
|
24 | 25 | const { p } = setup()
|
25 |
| - expect(p.textContent).toMatch(/^Clicked: 0 times/) |
| 26 | + expect(p.text()).toMatch(/^Clicked: 0 times/) |
26 | 27 | })
|
27 | 28 |
|
28 | 29 | it('first button should call onIncrement', () => {
|
29 | 30 | const { buttons, actions } = setup()
|
30 |
| - TestUtils.Simulate.click(buttons[0]) |
| 31 | + buttons.at(0).simulate('click') |
31 | 32 | expect(actions.onIncrement).toHaveBeenCalled()
|
32 | 33 | })
|
33 | 34 |
|
34 | 35 | it('second button should call onDecrement', () => {
|
35 | 36 | const { buttons, actions } = setup()
|
36 |
| - TestUtils.Simulate.click(buttons[1]) |
| 37 | + buttons.at(1).simulate('click') |
37 | 38 | expect(actions.onDecrement).toHaveBeenCalled()
|
38 | 39 | })
|
39 | 40 |
|
40 | 41 | it('third button should not call onIncrement if the counter is even', () => {
|
41 | 42 | const { buttons, actions } = setup(42)
|
42 |
| - TestUtils.Simulate.click(buttons[2]) |
| 43 | + buttons.at(2).simulate('click') |
43 | 44 | expect(actions.onIncrement).toNotHaveBeenCalled()
|
44 | 45 | })
|
45 | 46 |
|
46 | 47 | it('third button should call onIncrement if the counter is odd', () => {
|
47 | 48 | const { buttons, actions } = setup(43)
|
48 |
| - TestUtils.Simulate.click(buttons[2]) |
| 49 | + buttons.at(2).simulate('click') |
49 | 50 | expect(actions.onIncrement).toHaveBeenCalled()
|
50 | 51 | })
|
51 | 52 |
|
52 | 53 | it('third button should call onIncrement if the counter is odd and negative', () => {
|
53 | 54 | const { buttons, actions } = setup(-43)
|
54 |
| - TestUtils.Simulate.click(buttons[2]) |
| 55 | + buttons.at(2).simulate('click') |
55 | 56 | expect(actions.onIncrement).toHaveBeenCalled()
|
56 | 57 | })
|
57 | 58 |
|
58 | 59 | it('fourth button should call onIncrement in a second', (done) => {
|
59 | 60 | const { buttons, actions } = setup()
|
60 |
| - TestUtils.Simulate.click(buttons[3]) |
| 61 | + buttons.at(3).simulate('click') |
61 | 62 | setTimeout(() => {
|
62 | 63 | expect(actions.onIncrement).toHaveBeenCalled()
|
63 | 64 | done()
|
|
0 commit comments