@@ -24,6 +24,27 @@ describe('useCollections', () => {
2424 expect ( result . current . state ) . toEqual ( 'IDLE' ) ;
2525 } ) ;
2626
27+ it ( 'reloads collections' , async ( ) => {
28+ fetch
29+ . mockResponseOnce ( JSON . stringify ( { links : [ ] } ) , { url : 'https://fake-stac-api.net' } )
30+ . mockResponseOnce ( JSON . stringify ( { data : 'original' } ) )
31+ . mockResponseOnce ( JSON . stringify ( { data : 'reloaded' } ) ) ;
32+
33+ const { result, waitForNextUpdate } = renderHook (
34+ ( ) => useCollections ( ) ,
35+ { wrapper }
36+ ) ;
37+ await waitForNextUpdate ( ) ;
38+ await waitForNextUpdate ( ) ;
39+ expect ( result . current . collections ) . toEqual ( { data : 'original' } ) ;
40+
41+ expect ( result . current . state ) . toEqual ( 'IDLE' ) ;
42+ act ( ( ) => result . current . reload ( ) ) ;
43+
44+ await waitForNextUpdate ( ) ;
45+ expect ( result . current . collections ) . toEqual ( { data : 'reloaded' } ) ;
46+ } ) ;
47+
2748 it ( 'handles error with JSON response' , async ( ) => {
2849 fetch
2950 . mockResponseOnce ( JSON . stringify ( { links : [ ] } ) , { url : 'https://fake-stac-api.net' } )
@@ -61,25 +82,4 @@ describe('useCollections', () => {
6182 detail : 'Wrong query'
6283 } ) ;
6384 } ) ;
64-
65- it ( 'reloads collections' , async ( ) => {
66- fetch
67- . mockResponseOnce ( JSON . stringify ( { links : [ ] } ) , { url : 'https://fake-stac-api.net' } )
68- . mockResponseOnce ( JSON . stringify ( { data : 'original' } ) )
69- . mockResponseOnce ( JSON . stringify ( { data : 'reloaded' } ) ) ;
70-
71- const { result, waitForNextUpdate } = renderHook (
72- ( ) => useCollections ( ) ,
73- { wrapper }
74- ) ;
75- await waitForNextUpdate ( ) ;
76- await waitForNextUpdate ( ) ;
77- expect ( result . current . collections ) . toEqual ( { data : 'original' } ) ;
78-
79- expect ( result . current . state ) . toEqual ( 'IDLE' ) ;
80- act ( ( ) => result . current . reload ( ) ) ;
81-
82- await waitForNextUpdate ( ) ;
83- expect ( result . current . collections ) . toEqual ( { data : 'reloaded' } ) ;
84- } ) ;
8585} ) ;
0 commit comments