7
7
* @flow
8
8
*/
9
9
10
+ import { getVersionedRenderImplementation } from './utils' ;
11
+
10
12
describe ( 'useEditableValue' , ( ) => {
11
13
let act ;
12
14
let React ;
13
- let legacyRender ;
14
15
let useEditableValue ;
15
16
16
17
beforeEach ( ( ) => {
17
18
const utils = require ( './utils' ) ;
18
19
act = utils . act ;
19
- legacyRender = utils . legacyRender ;
20
20
21
21
React = require ( 'react' ) ;
22
22
23
23
useEditableValue = require ( '../devtools/views/hooks' ) . useEditableValue ;
24
24
} ) ;
25
25
26
+ const { render} = getVersionedRenderImplementation ( ) ;
27
+
26
28
it ( 'should not cause a loop with values like NaN' , ( ) => {
27
29
let state ;
28
30
@@ -32,8 +34,8 @@ describe('useEditableValue', () => {
32
34
return null ;
33
35
}
34
36
35
- const container = document . createElement ( 'div' ) ;
36
- legacyRender ( < Example /> , container ) ;
37
+ act ( ( ) => render ( < Example /> ) ) ;
38
+
37
39
expect ( state . editableValue ) . toEqual ( 'NaN' ) ;
38
40
expect ( state . externalValue ) . toEqual ( NaN ) ;
39
41
expect ( state . parsedValue ) . toEqual ( NaN ) ;
@@ -50,8 +52,8 @@ describe('useEditableValue', () => {
50
52
return null ;
51
53
}
52
54
53
- const container = document . createElement ( 'div' ) ;
54
- legacyRender ( < Example value = { 1 } /> , container ) ;
55
+ act ( ( ) => render ( < Example value = { 1 } /> ) ) ;
56
+
55
57
expect ( state . editableValue ) . toEqual ( '1' ) ;
56
58
expect ( state . externalValue ) . toEqual ( 1 ) ;
57
59
expect ( state . parsedValue ) . toEqual ( 1 ) ;
@@ -60,7 +62,8 @@ describe('useEditableValue', () => {
60
62
61
63
// If there are NO pending changes,
62
64
// an update to the external prop value should override the local/pending value.
63
- legacyRender ( < Example value = { 2 } /> , container ) ;
65
+ act ( ( ) => render ( < Example value = { 2 } /> ) ) ;
66
+
64
67
expect ( state . editableValue ) . toEqual ( '2' ) ;
65
68
expect ( state . externalValue ) . toEqual ( 2 ) ;
66
69
expect ( state . parsedValue ) . toEqual ( 2 ) ;
@@ -78,8 +81,8 @@ describe('useEditableValue', () => {
78
81
return null ;
79
82
}
80
83
81
- const container = document . createElement ( 'div' ) ;
82
- legacyRender ( < Example value = { 1 } /> , container ) ;
84
+ act ( ( ) => render ( < Example value = { 1 } /> ) ) ;
85
+
83
86
expect ( state . editableValue ) . toEqual ( '1' ) ;
84
87
expect ( state . externalValue ) . toEqual ( 1 ) ;
85
88
expect ( state . parsedValue ) . toEqual ( 1 ) ;
@@ -102,7 +105,8 @@ describe('useEditableValue', () => {
102
105
103
106
// If there ARE pending changes,
104
107
// an update to the external prop value should NOT override the local/pending value.
105
- legacyRender ( < Example value = { 3 } /> , container ) ;
108
+ act ( ( ) => render ( < Example value = { 3 } /> ) ) ;
109
+
106
110
expect ( state . editableValue ) . toEqual ( '2' ) ;
107
111
expect ( state . externalValue ) . toEqual ( 3 ) ;
108
112
expect ( state . parsedValue ) . toEqual ( 2 ) ;
@@ -120,8 +124,8 @@ describe('useEditableValue', () => {
120
124
return null ;
121
125
}
122
126
123
- const container = document . createElement ( 'div' ) ;
124
- legacyRender ( < Example value = { 1 } /> , container ) ;
127
+ act ( ( ) => render ( < Example value = { 1 } /> ) ) ;
128
+
125
129
expect ( state . editableValue ) . toEqual ( '1' ) ;
126
130
expect ( state . externalValue ) . toEqual ( 1 ) ;
127
131
expect ( state . parsedValue ) . toEqual ( 1 ) ;
@@ -153,8 +157,8 @@ describe('useEditableValue', () => {
153
157
return null ;
154
158
}
155
159
156
- const container = document . createElement ( 'div' ) ;
157
- legacyRender ( < Example value = { 1 } /> , container ) ;
160
+ act ( ( ) => render ( < Example value = { 1 } /> ) ) ;
161
+
158
162
expect ( state . editableValue ) . toEqual ( '1' ) ;
159
163
expect ( state . externalValue ) . toEqual ( 1 ) ;
160
164
expect ( state . parsedValue ) . toEqual ( 1 ) ;
0 commit comments