File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 11import { act , renderHook , waitFor } from '@testing-library/react' ;
2+ import { StrictMode } from 'react' ;
23import { useLoader } from './useLoader' ;
34
45describe ( 'useLoader' , ( ) => {
@@ -404,4 +405,34 @@ describe('useLoader', () => {
404405
405406 await waitFor ( ( ) => expect ( secondTime . current ) . toBe ( 'foo' ) ) ;
406407 } ) ;
408+
409+ it ( 'should update the content in StrictMode' , async ( ) => {
410+ jest . useFakeTimers ( ) ;
411+
412+ const delay = 10 ;
413+ const loader = jest . fn (
414+ ( ) => new Promise ( resolve => {
415+ setTimeout ( ( ) => resolve ( 'foo' ) , delay ) ;
416+ } ) ,
417+ ) ;
418+
419+ const { result} = renderHook (
420+ ( ) => useLoader ( {
421+ cacheKey : cacheKey . current ( ) ,
422+ loader : loader ,
423+ initial : 'bar' ,
424+ } ) ,
425+ {
426+ wrapper : StrictMode ,
427+ } ,
428+ ) ;
429+
430+ // Let the loader resolve
431+ await act ( async ( ) => {
432+ jest . advanceTimersByTime ( delay ) ;
433+ await flushPromises ( ) ;
434+ } ) ;
435+
436+ await waitFor ( ( ) => expect ( result . current ) . toBe ( 'foo' ) ) ;
437+ } ) ;
407438} ) ;
You can’t perform that action at this time.
0 commit comments