@@ -131,25 +131,48 @@ describe('Fast Refresh', () => {
131
131
};
132
132
133
133
function Child() {
134
- return null ;
134
+ return <div /> ;
135
135
};
136
136
137
137
export default Parent;
138
138
` ) ;
139
+ expect ( store ) . toMatchInlineSnapshot ( `
140
+ [root]
141
+ ▾ <Parent>
142
+ <Child key="A">
143
+ ` ) ;
144
+
145
+ let element = container . firstChild ;
146
+ expect ( container . firstChild ) . not . toBe ( null ) ;
147
+
148
+ patch ( `
149
+ function Parent() {
150
+ return <Child key="A" />;
151
+ };
152
+
153
+ function Child() {
154
+ return <div />;
155
+ };
139
156
157
+ export default Parent;
158
+ ` ) ;
140
159
expect ( store ) . toMatchInlineSnapshot ( `
141
160
[root]
142
161
▾ <Parent>
143
162
<Child key="A">
144
163
` ) ;
145
164
165
+ // State is preserved; this verifies that Fast Refresh is wired up.
166
+ expect ( container . firstChild ) . toBe ( element ) ;
167
+ element = container . firstChild ;
168
+
146
169
patch ( `
147
170
function Parent() {
148
171
return <Child key="B" />;
149
172
};
150
173
151
174
function Child() {
152
- return null ;
175
+ return <div /> ;
153
176
};
154
177
155
178
export default Parent;
@@ -159,6 +182,9 @@ describe('Fast Refresh', () => {
159
182
▾ <Parent>
160
183
<Child key="B">
161
184
` ) ;
185
+
186
+ // State is reset because hooks changed.
187
+ expect ( container . firstChild ) . not . toBe ( element ) ;
162
188
} ) ;
163
189
164
190
it ( 'should not break when there are warnings in between patching' , ( ) => {
@@ -168,10 +194,8 @@ describe('Fast Refresh', () => {
168
194
169
195
export default function Component() {
170
196
const [state, setState] = useState(1);
171
-
172
197
console.warn("Expected warning during render");
173
-
174
- return <div />;
198
+ return null;
175
199
}
176
200
` ) ;
177
201
} ) ;
@@ -181,56 +205,56 @@ describe('Fast Refresh', () => {
181
205
<Component> ⚠
182
206
` ) ;
183
207
184
- let element = container . firstChild ;
185
-
186
208
withErrorsOrWarningsIgnored ( [ 'Expected warning during render' ] , ( ) => {
187
209
patch ( `
188
- const {useState} = React;
210
+ const {useEffect, useState} = React;
189
211
190
212
export default function Component() {
191
213
const [state, setState] = useState(1);
192
-
193
214
console.warn("Expected warning during render");
194
-
195
- return <div id="one" />;
215
+ return null;
196
216
}
197
217
` ) ;
198
218
} ) ;
199
-
200
- // This is the same component type, so the warning count carries over.
201
219
expect ( store ) . toMatchInlineSnapshot ( `
202
220
✕ 0, ⚠ 2
203
221
[root]
204
222
<Component> ⚠
205
223
` ) ;
206
224
207
- // State is preserved; this verifies that Fast Refresh is wired up.
208
- expect ( container . firstChild ) . toBe ( element ) ;
209
- element = container . firstChild ;
210
-
211
225
withErrorsOrWarningsIgnored ( [ 'Expected warning during render' ] , ( ) => {
212
226
patch ( `
213
227
const {useEffect, useState} = React;
214
228
215
229
export default function Component() {
216
- const [state, setState] = useState(3 );
230
+ const [state, setState] = useState(1 );
217
231
useEffect(() => {});
218
-
219
232
console.warn("Expected warning during render");
220
-
221
- return <div id="one" />;
233
+ return null;
222
234
}
223
235
` ) ;
224
236
} ) ;
225
-
226
- // This is a new component type, so the warning count has been reset.
227
237
expect ( store ) . toMatchInlineSnapshot ( `
228
238
✕ 0, ⚠ 1
229
239
[root]
230
240
<Component> ⚠
231
241
` ) ;
232
242
233
- // State is reset because hooks changed.
234
- expect ( container . firstChild ) . not . toBe ( element ) ;
243
+ withErrorsOrWarningsIgnored ( [ 'Expected warning during render' ] , ( ) => {
244
+ patch ( `
245
+ const {useEffect, useState} = React;
246
+
247
+ export default function Component() {
248
+ const [state, setState] = useState(1);
249
+ console.warn("Expected warning during render");
250
+ return null;
251
+ }
252
+ ` ) ;
253
+ } ) ;
254
+ expect ( store ) . toMatchInlineSnapshot ( `
255
+ ✕ 0, ⚠ 1
256
+ [root]
257
+ <Component> ⚠
258
+ ` ) ;
235
259
} ) ;
236
260
} ) ;
0 commit comments