@@ -80,9 +80,8 @@ describe('Select :: Search', () => {
8080  } ) 
8181
8282  describe ( 'Async search' ,  ( )  =>  { 
83-     const  searchInput  =  'searchString' 
84- 
8583    it ( 'performs async searching when the prop is present' ,  async  ( )  =>  { 
84+       const  searchInput  =  'searchString' 
8685      const  reducerSpy  =  jest . spyOn ( reducerImports ,  'reducer' ) 
8786      const  debounceTimeout  =  DEFAULT_ASYNC_SEARCH_DEBOUNCE 
8887      const  testTimeout  =  100 
@@ -172,6 +171,50 @@ describe('Select :: Search', () => {
172171      expect ( queryAllByText ( DEFAULT_ASYNC_SEARCHING_TEXT ) ) . toHaveLength ( 0 ) 
173172    } ) 
174173
174+     it ( 'uses a custom debounce time when the prop is specified' ,  async  ( )  =>  { 
175+       const  debounceTimeout  =  47 
176+       const  testTimeout  =  100 
177+       const  asyncSearch  =  jest . fn ( ( )  =>  { 
178+         return  new  Promise ( resolve  =>  { 
179+           setTimeout ( ( )  =>  { 
180+             resolve ( searchResultUserOptions ) 
181+           } ,  testTimeout ) 
182+         } ) 
183+       } ) 
184+ 
185+       const  {  container,  getAllByText }  =  render ( 
186+         < Select 
187+           { ...defaultProps } 
188+           asyncSearch = { asyncSearch } 
189+           asyncSearchDebounceTime = { debounceTimeout } 
190+         /> , 
191+       ) 
192+ 
193+       // just to be sure we get the menu open correctly... 
194+       const  containerEl  =  container . querySelector ( css ( '__container' ) ) 
195+       fireEvent . mouseDown ( containerEl  as  HTMLElement ) 
196+       const  optionsWrapper  =  container . querySelectorAll ( css ( '__optionsWrapper' ) ) 
197+       expect ( optionsWrapper ) . toHaveLength ( 1 ) 
198+ 
199+       const  inputEl  =  container . querySelector ( 'input' )  as  HTMLElement 
200+       fireEvent . change ( inputEl ,  {  target : {  value : 'hey there'  }  } ) 
201+       jest . advanceTimersByTime ( debounceTimeout  -  1 ) 
202+       expect ( asyncSearch ) . toHaveBeenCalledTimes ( 0 ) 
203+       jest . advanceTimersByTime ( 1 ) 
204+       expect ( asyncSearch ) . toHaveBeenCalledTimes ( 1 ) 
205+       expect ( asyncSearch ) . toHaveBeenCalledWith ( 'hey there' ) 
206+ 
207+       // now wait for our mock "API Search" and ensure we handle the results correctly 
208+       await  wait ( ( )  =>  { 
209+         jest . advanceTimersByTime ( testTimeout ) 
210+       } ) 
211+ 
212+       // uses the returned user set for the options 
213+       searchResultUserOptions . forEach ( result  =>  { 
214+         expect ( getAllByText ( getUserFullName ( result ) ) ) . toHaveLength ( 1 ) 
215+       } ) 
216+     } ) 
217+ 
175218    it ( 'resets options and ignore any pending debounced searches if search is empty' ,  async  ( )  =>  { 
176219      const  debounceTimeout  =  DEFAULT_ASYNC_SEARCH_DEBOUNCE 
177220      const  testTimeout  =  100 
0 commit comments