1
- import expect from 'expect'
2
1
import React from 'react'
3
2
import { shallow } from 'enzyme'
4
3
import Counter from './Counter'
5
4
6
5
function setup ( value = 0 ) {
7
6
const actions = {
8
- onIncrement : expect . createSpy ( ) ,
9
- onDecrement : expect . createSpy ( )
7
+ onIncrement : jest . fn ( ) ,
8
+ onDecrement : jest . fn ( )
10
9
}
11
10
const component = shallow (
12
11
< Counter value = { value } { ...actions } />
@@ -29,38 +28,38 @@ describe('Counter component', () => {
29
28
it ( 'first button should call onIncrement' , ( ) => {
30
29
const { buttons, actions } = setup ( )
31
30
buttons . at ( 0 ) . simulate ( 'click' )
32
- expect ( actions . onIncrement ) . toHaveBeenCalled ( )
31
+ expect ( actions . onIncrement ) . toBeCalled ( )
33
32
} )
34
33
35
34
it ( 'second button should call onDecrement' , ( ) => {
36
35
const { buttons, actions } = setup ( )
37
36
buttons . at ( 1 ) . simulate ( 'click' )
38
- expect ( actions . onDecrement ) . toHaveBeenCalled ( )
37
+ expect ( actions . onDecrement ) . toBeCalled ( )
39
38
} )
40
39
41
40
it ( 'third button should not call onIncrement if the counter is even' , ( ) => {
42
41
const { buttons, actions } = setup ( 42 )
43
42
buttons . at ( 2 ) . simulate ( 'click' )
44
- expect ( actions . onIncrement ) . toNotHaveBeenCalled ( )
43
+ expect ( actions . onIncrement ) . not . toBeCalled ( )
45
44
} )
46
45
47
46
it ( 'third button should call onIncrement if the counter is odd' , ( ) => {
48
47
const { buttons, actions } = setup ( 43 )
49
48
buttons . at ( 2 ) . simulate ( 'click' )
50
- expect ( actions . onIncrement ) . toHaveBeenCalled ( )
49
+ expect ( actions . onIncrement ) . toBeCalled ( )
51
50
} )
52
51
53
52
it ( 'third button should call onIncrement if the counter is odd and negative' , ( ) => {
54
53
const { buttons, actions } = setup ( - 43 )
55
54
buttons . at ( 2 ) . simulate ( 'click' )
56
- expect ( actions . onIncrement ) . toHaveBeenCalled ( )
55
+ expect ( actions . onIncrement ) . toBeCalled ( )
57
56
} )
58
57
59
58
it ( 'fourth button should call onIncrement in a second' , ( done ) => {
60
59
const { buttons, actions } = setup ( )
61
60
buttons . at ( 3 ) . simulate ( 'click' )
62
61
setTimeout ( ( ) => {
63
- expect ( actions . onIncrement ) . toHaveBeenCalled ( )
62
+ expect ( actions . onIncrement ) . toBeCalled ( )
64
63
done ( )
65
64
} , 1000 )
66
65
} )
0 commit comments