@@ -2,6 +2,7 @@ import fetch from 'jest-fetch-mock';
22import { renderHook , act } from '@testing-library/react-hooks' ;
33import useStacSearch from './useStacSearch' ;
44import StacApi from '../stac-api' ;
5+ import { Bbox } from '../types/stac' ;
56
67function parseRequestPayload ( mockApiCall ?: RequestInit ) {
78 if ( ! mockApiCall ) {
@@ -391,4 +392,27 @@ describe('useStacSearch', () => {
391392 expect ( fetch . mock . calls [ 1 ] [ 1 ] ?. method ) . toEqual ( 'GET' ) ;
392393 expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
393394 } ) ;
395+
396+ it ( 'should reset state with each new StacApi instance' , async ( ) => {
397+ const bbox : Bbox = [ - 0.59 , 51.24 , 0.30 , 51.74 ] ;
398+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
399+
400+ const { result, rerender, waitForNextUpdate } = renderHook (
401+ ( { stacApi } ) => useStacSearch ( stacApi ) , {
402+ initialProps : { stacApi } ,
403+ }
404+ ) ;
405+
406+ act ( ( ) => result . current . setBbox ( bbox ) ) ;
407+ act ( ( ) => result . current . submit ( ) ) ;
408+ await waitForNextUpdate ( ) ;
409+
410+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
411+ expect ( result . current . bbox ) . toEqual ( bbox ) ;
412+
413+ const newStac = new StacApi ( 'https://otherstack.com' ) ;
414+ rerender ( { stacApi : newStac } ) ;
415+ expect ( result . current . results ) . toBeUndefined ( ) ;
416+ expect ( result . current . bbox ) . toBeUndefined ( ) ;
417+ } ) ;
394418} ) ;
0 commit comments