11/*eslint-disable react/prop-types*/
22
3- import expect from 'expect'
43import React , { Component } from 'react'
54import PropTypes from 'prop-types'
65import TestUtils from 'react-dom/test-utils'
@@ -36,7 +35,7 @@ describe('React', () => {
3635 < Provider store = { store } >
3736 < div />
3837 </ Provider >
39- ) ) . toNotThrow ( )
38+ ) ) . not . toThrow ( )
4039
4140 expect ( ( ) => TestUtils . renderIntoDocument (
4241 < Provider store = { store } >
@@ -57,14 +56,14 @@ describe('React', () => {
5756 it ( 'should add the store to the child context' , ( ) => {
5857 const store = createStore ( ( ) => ( { } ) )
5958
60- const spy = expect . spyOn ( console , 'error' )
59+ const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
6160 const tree = TestUtils . renderIntoDocument (
6261 < Provider store = { store } >
6362 < Child />
6463 </ Provider >
6564 )
66- spy . destroy ( )
67- expect ( spy . calls . length ) . toBe ( 0 )
65+ spy . mockRestore ( )
66+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
6867
6968 const child = TestUtils . findRenderedComponentWithType ( tree , Child )
7069 expect ( child . context . store ) . toBe ( store )
@@ -75,14 +74,14 @@ describe('React', () => {
7574 const CustomProvider = createProvider ( 'customStoreKey' ) ;
7675 const CustomChild = createChild ( 'customStoreKey' ) ;
7776
78- const spy = expect . spyOn ( console , 'error' ) ;
77+ const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
7978 const tree = TestUtils . renderIntoDocument (
8079 < CustomProvider store = { store } >
8180 < CustomChild />
8281 </ CustomProvider >
8382 )
84- spy . destroy ( )
85- expect ( spy . calls . length ) . toBe ( 0 )
83+ spy . mockRestore ( )
84+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
8685
8786 const child = TestUtils . findRenderedComponentWithType ( tree , CustomChild )
8887 expect ( child . context . customStoreKey ) . toBe ( store )
@@ -111,33 +110,33 @@ describe('React', () => {
111110 const child = TestUtils . findRenderedComponentWithType ( container , Child )
112111 expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
113112
114- let spy = expect . spyOn ( console , 'error' )
113+ let spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
115114 container . setState ( { store : store2 } )
116- spy . destroy ( )
115+ spy . mockRestore ( )
117116
118117 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 (
121120 '<Provider> does not support changing `store` on the fly. ' +
122121 'It is most likely that you see this error because you updated to ' +
123122 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
124123 'automatically. See https://github.com/reactjs/react-redux/releases/' +
125124 'tag/v2.0.0 for the migration instructions.'
126125 )
127126
128- spy = expect . spyOn ( console , 'error' )
127+ spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
129128 container . setState ( { store : store3 } )
130- spy . destroy ( )
129+ spy . mockRestore ( )
131130
132131 expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
133- expect ( spy . calls . length ) . toBe ( 0 )
132+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
134133 } )
135134
136135 it ( 'should handle subscriptions correctly when there is nested Providers' , ( ) => {
137136 const reducer = ( state = 0 , action ) => ( action . type === 'INC' ? state + 1 : state )
138137
139138 const innerStore = createStore ( reducer )
140- const innerMapStateToProps = expect . createSpy ( ) . andCall ( state => ( { count : state } ) )
139+ const innerMapStateToProps = jest . fn ( state => ( { count : state } ) )
141140 @connect ( innerMapStateToProps )
142141 class Inner extends Component {
143142 render ( ) { return < div > { this . props . count } </ div > }
@@ -150,10 +149,10 @@ describe('React', () => {
150149 }
151150
152151 TestUtils . renderIntoDocument ( < Provider store = { outerStore } > < Outer /> </ Provider > )
153- expect ( innerMapStateToProps . calls . length ) . toBe ( 1 )
152+ expect ( innerMapStateToProps ) . toHaveBeenCalledTimes ( 1 )
154153
155154 innerStore . dispatch ( { type : 'INC' } )
156- expect ( innerMapStateToProps . calls . length ) . toBe ( 2 )
155+ expect ( innerMapStateToProps ) . toHaveBeenCalledTimes ( 2 )
157156 } )
158157 } )
159158
0 commit comments