1
1
/*eslint-disable react/prop-types*/
2
2
3
- import expect from 'expect'
4
3
import React , { Component } from 'react'
5
4
import PropTypes from 'prop-types'
6
5
import TestUtils from 'react-dom/test-utils'
@@ -36,7 +35,7 @@ describe('React', () => {
36
35
< Provider store = { store } >
37
36
< div />
38
37
</ Provider >
39
- ) ) . toNotThrow ( )
38
+ ) ) . not . toThrow ( )
40
39
41
40
expect ( ( ) => TestUtils . renderIntoDocument (
42
41
< Provider store = { store } >
@@ -57,14 +56,14 @@ describe('React', () => {
57
56
it ( 'should add the store to the child context' , ( ) => {
58
57
const store = createStore ( ( ) => ( { } ) )
59
58
60
- const spy = expect . spyOn ( console , 'error' )
59
+ const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
61
60
const tree = TestUtils . renderIntoDocument (
62
61
< Provider store = { store } >
63
62
< Child />
64
63
</ Provider >
65
64
)
66
- spy . destroy ( )
67
- expect ( spy . calls . length ) . toBe ( 0 )
65
+ spy . mockRestore ( )
66
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
68
67
69
68
const child = TestUtils . findRenderedComponentWithType ( tree , Child )
70
69
expect ( child . context . store ) . toBe ( store )
@@ -75,14 +74,14 @@ describe('React', () => {
75
74
const CustomProvider = createProvider ( 'customStoreKey' ) ;
76
75
const CustomChild = createChild ( 'customStoreKey' ) ;
77
76
78
- const spy = expect . spyOn ( console , 'error' ) ;
77
+ const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
79
78
const tree = TestUtils . renderIntoDocument (
80
79
< CustomProvider store = { store } >
81
80
< CustomChild />
82
81
</ CustomProvider >
83
82
)
84
- spy . destroy ( )
85
- expect ( spy . calls . length ) . toBe ( 0 )
83
+ spy . mockRestore ( )
84
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
86
85
87
86
const child = TestUtils . findRenderedComponentWithType ( tree , CustomChild )
88
87
expect ( child . context . customStoreKey ) . toBe ( store )
@@ -111,33 +110,33 @@ describe('React', () => {
111
110
const child = TestUtils . findRenderedComponentWithType ( container , Child )
112
111
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
113
112
114
- let spy = expect . spyOn ( console , 'error' )
113
+ let spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
115
114
container . setState ( { store : store2 } )
116
- spy . destroy ( )
115
+ spy . mockRestore ( )
117
116
118
117
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 (
121
120
'<Provider> does not support changing `store` on the fly. ' +
122
121
'It is most likely that you see this error because you updated to ' +
123
122
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
124
123
'automatically. See https://github.com/reactjs/react-redux/releases/' +
125
124
'tag/v2.0.0 for the migration instructions.'
126
125
)
127
126
128
- spy = expect . spyOn ( console , 'error' )
127
+ spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
129
128
container . setState ( { store : store3 } )
130
- spy . destroy ( )
129
+ spy . mockRestore ( )
131
130
132
131
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
133
- expect ( spy . calls . length ) . toBe ( 0 )
132
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
134
133
} )
135
134
136
135
it ( 'should handle subscriptions correctly when there is nested Providers' , ( ) => {
137
136
const reducer = ( state = 0 , action ) => ( action . type === 'INC' ? state + 1 : state )
138
137
139
138
const innerStore = createStore ( reducer )
140
- const innerMapStateToProps = expect . createSpy ( ) . andCall ( state => ( { count : state } ) )
139
+ const innerMapStateToProps = jest . fn ( state => ( { count : state } ) )
141
140
@connect ( innerMapStateToProps )
142
141
class Inner extends Component {
143
142
render ( ) { return < div > { this . props . count } </ div > }
@@ -150,10 +149,10 @@ describe('React', () => {
150
149
}
151
150
152
151
TestUtils . renderIntoDocument ( < Provider store = { outerStore } > < Outer /> </ Provider > )
153
- expect ( innerMapStateToProps . calls . length ) . toBe ( 1 )
152
+ expect ( innerMapStateToProps ) . toHaveBeenCalledTimes ( 1 )
154
153
155
154
innerStore . dispatch ( { type : 'INC' } )
156
- expect ( innerMapStateToProps . calls . length ) . toBe ( 2 )
155
+ expect ( innerMapStateToProps ) . toHaveBeenCalledTimes ( 2 )
157
156
} )
158
157
} )
159
158
0 commit comments