1
- import { renderHook } from '@testing-library/react'
1
+ import { renderHook , waitFor } from '@testing-library/react'
2
2
import { useLoadingState } from '../useLoadingState'
3
3
import { Box } from '@cloudscape-design/components'
4
4
import React from 'react'
@@ -44,9 +44,9 @@ jest.mock('../../model', () => {
44
44
} )
45
45
46
46
function 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 ) )
50
50
}
51
51
52
52
function expectDataNotToBeRequested ( ) {
@@ -114,12 +114,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
114
114
} )
115
115
116
116
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} )
123
118
124
119
expectDataToBeRequested ( )
125
120
} )
@@ -139,12 +134,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
139
134
} )
140
135
141
136
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} )
148
138
149
139
expectDataToBeRequested ( )
150
140
} )
@@ -166,12 +156,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
166
156
} )
167
157
168
158
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} )
175
160
176
161
expectDataToBeRequested ( )
177
162
} )
@@ -259,10 +244,9 @@ describe('given a hook to load all the data necessary for the app to boot', () =
259
244
done ( )
260
245
} )
261
246
262
- const { waitForNextUpdate } = renderHook ( ( ) => useLoadingState ( < > </ > ) , {
247
+ renderHook ( ( ) => useLoadingState ( < > </ > ) , {
263
248
wrapper,
264
249
} )
265
- waitForNextUpdate ( )
266
250
} )
267
251
} )
268
252
} )
0 commit comments