1- import { cleanup } from '@testing-library/react' ;
2- import { renderHook , act } from '@testing-library/react-hooks' ;
1+ import { cleanup , renderHook , act , waitFor } from '@testing-library/react' ;
32import { FetchMock } from 'jest-fetch-mock' ;
43import {
54 defaultHttpReqConfig ,
@@ -153,7 +152,7 @@ describe('use-http-request', () => {
153152 test ( 'should automatically perform the request on mount' , async ( ) => {
154153 fetch . mockResponseOnce ( JSON . stringify ( fetchResponse ) ) ;
155154
156- const { result, waitForNextUpdate } = renderHook (
155+ const { result } = renderHook (
157156 ( ) => useHttpRequest ( { fetchOnBootstrap : true , initialData : { } } ) ,
158157 {
159158 wrapper : HttpClientProviderConfigFixture . create ( ) ,
@@ -166,7 +165,13 @@ describe('use-http-request', () => {
166165 expect ( result . current [ 0 ] . isLoading ) . toBe ( true ) ;
167166 expect ( result . current [ 0 ] . pristine ) . toBe ( false ) ;
168167
169- await waitForNextUpdate ( ) ;
168+ // await waitForNextUpdate();
169+ await waitFor (
170+ ( ) => {
171+ expect ( result . current [ 0 ] . isLoading ) . toBe ( false ) ;
172+ } ,
173+ { interval : 1 }
174+ ) ;
170175
171176 expect ( result . current [ 0 ] . data ) . toEqual ( fetchResponse ) ;
172177 expect ( result . current [ 0 ] . error ) . toBeNull ( ) ;
0 commit comments