You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('should asynchronously load a lazy component',async()=>{
294
-
letresolveA;
295
-
constLazyA=React.lazy(()=>{
296
-
returnnewPromise(r=>{
297
-
resolveA=r;
294
+
constoriginalConsoleError=console.error;
295
+
constmockError=jest.fn();
296
+
console.error=(...args)=>{
297
+
if(args.length>1){
298
+
if(typeofargs[1]==='object'){
299
+
mockError(args[0].split('\n')[0]);
300
+
return;
301
+
}
302
+
}
303
+
mockError(...args.map(normalizeCodeLocInfo));
304
+
};
305
+
306
+
try{
307
+
letresolveA;
308
+
constLazyA=React.lazy(()=>{
309
+
returnnewPromise(r=>{
310
+
resolveA=r;
311
+
});
298
312
});
299
-
});
300
313
301
-
letresolveB;
302
-
constLazyB=React.lazy(()=>{
303
-
returnnewPromise(r=>{
304
-
resolveB=r;
314
+
letresolveB;
315
+
constLazyB=React.lazy(()=>{
316
+
returnnewPromise(r=>{
317
+
resolveB=r;
318
+
});
305
319
});
306
-
});
307
320
308
-
functionTextWithPunctuation({text, punctuation}){
309
-
return<Texttext={text+punctuation}/>;
310
-
}
311
-
// This tests that default props of the inner element is resolved.
312
-
TextWithPunctuation.defaultProps={
313
-
punctuation: '!',
314
-
};
321
+
functionTextWithPunctuation({text, punctuation}){
322
+
return<Texttext={text+punctuation}/>;
323
+
}
324
+
// This tests that default props of the inner element is resolved.
325
+
TextWithPunctuation.defaultProps={
326
+
punctuation: '!',
327
+
};
315
328
316
-
awaitact(async()=>{
317
-
const{pipe}=renderToPipeableStream(
318
-
<div>
319
-
<div>
320
-
<Suspensefallback={<Texttext="Loading..."/>}>
321
-
<LazyAtext="Hello"/>
322
-
</Suspense>
323
-
</div>
329
+
awaitact(async()=>{
330
+
const{pipe}=renderToPipeableStream(
324
331
<div>
325
-
<Suspensefallback={<Texttext="Loading..."/>}>
326
-
<LazyBtext="world"/>
327
-
</Suspense>
328
-
</div>
332
+
<div>
333
+
<Suspensefallback={<Texttext="Loading..."/>}>
334
+
<LazyAtext="Hello"/>
335
+
</Suspense>
336
+
</div>
337
+
<div>
338
+
<Suspensefallback={<Texttext="Loading..."/>}>
339
+
<LazyBtext="world"/>
340
+
</Suspense>
341
+
</div>
342
+
</div>,
343
+
);
344
+
pipe(writable);
345
+
});
346
+
347
+
expect(getVisibleChildren(container)).toEqual(
348
+
<div>
349
+
<div>Loading...</div>
350
+
<div>Loading...</div>
351
+
</div>,
352
+
);
353
+
awaitact(async()=>{
354
+
resolveA({default: Text});
355
+
});
356
+
expect(getVisibleChildren(container)).toEqual(
357
+
<div>
358
+
<div>Hello</div>
359
+
<div>Loading...</div>
360
+
</div>,
361
+
);
362
+
awaitact(async()=>{
363
+
resolveB({default: TextWithPunctuation});
364
+
});
365
+
expect(getVisibleChildren(container)).toEqual(
366
+
<div>
367
+
<div>Hello</div>
368
+
<div>world!</div>
329
369
</div>,
330
370
);
331
-
pipe(writable);
332
-
});
333
371
334
-
expect(getVisibleChildren(container)).toEqual(
335
-
<div>
336
-
<div>Loading...</div>
337
-
<div>Loading...</div>
338
-
</div>,
339
-
);
340
-
awaitact(async()=>{
341
-
resolveA({default: Text});
342
-
});
343
-
expect(getVisibleChildren(container)).toEqual(
344
-
<div>
345
-
<div>Hello</div>
346
-
<div>Loading...</div>
347
-
</div>,
348
-
);
349
-
awaitact(async()=>{
350
-
resolveB({default: TextWithPunctuation});
351
-
});
352
-
expect(getVisibleChildren(container)).toEqual(
353
-
<div>
354
-
<div>Hello</div>
355
-
<div>world!</div>
356
-
</div>,
357
-
);
372
+
if(__DEV__){
373
+
expect(mockError).toHaveBeenCalledWith(
374
+
'Warning: %s: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.%s',
375
+
'TextWithPunctuation',
376
+
'\n in TextWithPunctuation (at **)\n'+
377
+
' in Lazy (at **)\n'+
378
+
' in Suspense (at **)\n'+
379
+
' in div (at **)\n'+
380
+
' in div (at **)',
381
+
);
382
+
}else{
383
+
expect(mockError).not.toHaveBeenCalled();
384
+
}
385
+
}finally{
386
+
console.error=originalConsoleError;
387
+
}
358
388
});
359
389
360
390
it('#23331: does not warn about hydration mismatches if something suspended in an earlier sibling',async()=>{
0 commit comments