1- import { renderHook } from '@testing-library/react'
1+ import { renderHook , waitFor } from '@testing-library/react'
22import { useLoadingState } from '../useLoadingState'
33import { Box } from '@cloudscape-design/components'
44import React from 'react'
@@ -44,9 +44,9 @@ jest.mock('../../model', () => {
4444} )
4545
4646function expectDataToBeRequested ( ) {
47- expect ( mockGetAppConfig ) . toHaveBeenCalledTimes ( 1 )
48- expect ( mockGetIdentity ) . toHaveBeenCalledTimes ( 1 )
49- expect ( mockGetVersion ) . toHaveBeenCalledTimes ( 1 )
47+ waitFor ( ( ) => expect ( mockGetAppConfig ) . toHaveBeenCalledTimes ( 1 ) )
48+ waitFor ( ( ) => expect ( mockGetIdentity ) . toHaveBeenCalledTimes ( 1 ) )
49+ waitFor ( ( ) => expect ( mockGetVersion ) . toHaveBeenCalledTimes ( 1 ) )
5050}
5151
5252function expectDataNotToBeRequested ( ) {
@@ -114,12 +114,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
114114 } )
115115
116116 it ( 'should request the data' , async ( ) => {
117- const { waitForNextUpdate} = renderHook (
118- ( ) => useLoadingState ( < Box > </ Box > ) ,
119- { wrapper} ,
120- )
121-
122- await waitForNextUpdate ( )
117+ renderHook ( ( ) => useLoadingState ( < Box > </ Box > ) , { wrapper} )
123118
124119 expectDataToBeRequested ( )
125120 } )
@@ -139,12 +134,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
139134 } )
140135
141136 it ( 'should request the data' , async ( ) => {
142- const { waitForNextUpdate} = renderHook (
143- ( ) => useLoadingState ( < Box > </ Box > ) ,
144- { wrapper} ,
145- )
146-
147- await waitForNextUpdate ( )
137+ renderHook ( ( ) => useLoadingState ( < Box > </ Box > ) , { wrapper} )
148138
149139 expectDataToBeRequested ( )
150140 } )
@@ -166,12 +156,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
166156 } )
167157
168158 it ( 'should request the data' , async ( ) => {
169- const { waitForNextUpdate} = renderHook (
170- ( ) => useLoadingState ( < Box > </ Box > ) ,
171- { wrapper} ,
172- )
173-
174- await waitForNextUpdate ( )
159+ renderHook ( ( ) => useLoadingState ( < Box > </ Box > ) , { wrapper} )
175160
176161 expectDataToBeRequested ( )
177162 } )
@@ -259,10 +244,9 @@ describe('given a hook to load all the data necessary for the app to boot', () =
259244 done ( )
260245 } )
261246
262- const { waitForNextUpdate } = renderHook ( ( ) => useLoadingState ( < > </ > ) , {
247+ renderHook ( ( ) => useLoadingState ( < > </ > ) , {
263248 wrapper,
264249 } )
265- waitForNextUpdate ( )
266250 } )
267251 } )
268252 } )
0 commit comments