2
2
3
3
import React , { Component } from 'react'
4
4
import PropTypes from 'prop-types'
5
- import TestUtils from 'react-dom/ test-utils '
5
+ import TestRenderer from 'react-test-renderer '
6
6
import { createStore } from 'redux'
7
7
import { Provider , createProvider , connect } from '../../src/index'
8
8
@@ -33,18 +33,18 @@ describe('React', () => {
33
33
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
34
34
35
35
try {
36
- expect ( ( ) => TestUtils . renderIntoDocument (
36
+ expect ( ( ) => TestRenderer . create (
37
37
< Provider store = { store } >
38
38
< div />
39
39
</ Provider >
40
40
) ) . not . toThrow ( )
41
41
42
- expect ( ( ) => TestUtils . renderIntoDocument (
42
+ expect ( ( ) => TestRenderer . create (
43
43
< Provider store = { store } >
44
44
</ Provider >
45
45
) ) . toThrow ( / a s i n g l e R e a c t e l e m e n t c h i l d / )
46
46
47
- expect ( ( ) => TestUtils . renderIntoDocument (
47
+ expect ( ( ) => TestRenderer . create (
48
48
< Provider store = { store } >
49
49
< div />
50
50
< div />
@@ -60,15 +60,15 @@ describe('React', () => {
60
60
const store = createStore ( ( ) => ( { } ) )
61
61
62
62
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
63
- const tree = TestUtils . renderIntoDocument (
63
+ const testRenderer = TestRenderer . create (
64
64
< Provider store = { store } >
65
65
< Child />
66
66
</ Provider >
67
67
)
68
68
spy . mockRestore ( )
69
69
expect ( spy ) . toHaveBeenCalledTimes ( 0 )
70
70
71
- const child = TestUtils . findRenderedComponentWithType ( tree , Child )
71
+ const child = testRenderer . root . findByType ( Child ) . instance
72
72
expect ( child . context . store ) . toBe ( store )
73
73
} )
74
74
@@ -78,15 +78,15 @@ describe('React', () => {
78
78
const CustomChild = createChild ( 'customStoreKey' ) ;
79
79
80
80
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
81
- const tree = TestUtils . renderIntoDocument (
81
+ const testRenderer = TestRenderer . create (
82
82
< CustomProvider store = { store } >
83
83
< CustomChild />
84
84
</ CustomProvider >
85
85
)
86
86
spy . mockRestore ( )
87
87
expect ( spy ) . toHaveBeenCalledTimes ( 0 )
88
88
89
- const child = TestUtils . findRenderedComponentWithType ( tree , CustomChild )
89
+ const child = testRenderer . root . findByType ( CustomChild ) . instance
90
90
expect ( child . context . customStoreKey ) . toBe ( store )
91
91
} )
92
92
@@ -109,12 +109,12 @@ describe('React', () => {
109
109
}
110
110
}
111
111
112
- const container = TestUtils . renderIntoDocument ( < ProviderContainer /> )
113
- const child = TestUtils . findRenderedComponentWithType ( container , Child )
112
+ const testRenderer = TestRenderer . create ( < ProviderContainer /> )
113
+ const child = testRenderer . root . findByType ( Child ) . instance
114
114
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
115
115
116
116
let spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
117
- container . setState ( { store : store2 } )
117
+ testRenderer . root . instance . setState ( { store : store2 } )
118
118
spy . mockRestore ( )
119
119
120
120
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
@@ -128,7 +128,7 @@ describe('React', () => {
128
128
)
129
129
130
130
spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
131
- container . setState ( { store : store3 } )
131
+ testRenderer . root . instance . setState ( { store : store3 } )
132
132
spy . mockRestore ( )
133
133
134
134
expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
@@ -151,7 +151,7 @@ describe('React', () => {
151
151
render ( ) { return < Provider store = { innerStore } > < Inner /> </ Provider > }
152
152
}
153
153
154
- TestUtils . renderIntoDocument ( < Provider store = { outerStore } > < Outer /> </ Provider > )
154
+ TestRenderer . create ( < Provider store = { outerStore } > < Outer /> </ Provider > )
155
155
expect ( innerMapStateToProps ) . toHaveBeenCalledTimes ( 1 )
156
156
157
157
innerStore . dispatch ( { type : 'INC' } )
@@ -199,7 +199,7 @@ describe('React', () => {
199
199
}
200
200
}
201
201
202
- const tree = TestUtils . renderIntoDocument (
202
+ const testRenderer = TestRenderer . create (
203
203
< Provider store = { store } >
204
204
< Container />
205
205
</ Provider >
@@ -212,9 +212,8 @@ describe('React', () => {
212
212
expect ( childMapStateInvokes ) . toBe ( 2 )
213
213
214
214
// setState calls DOM handlers are batched
215
- const container = TestUtils . findRenderedComponentWithType ( tree , Container )
216
- const node = container . getWrappedInstance ( ) . refs . button
217
- TestUtils . Simulate . click ( node )
215
+ const button = testRenderer . root . findByType ( 'button' )
216
+ button . props . onClick ( )
218
217
expect ( childMapStateInvokes ) . toBe ( 3 )
219
218
220
219
// Provider uses unstable_batchedUpdates() under the hood
0 commit comments