@@ -5,6 +5,7 @@ import { QueryClient } from 'react-query';
5
5
6
6
import { CoreAdminContext } from '../core' ;
7
7
import { useGetList } from './useGetList' ;
8
+ import { DataProvider } from '../types' ;
8
9
9
10
const UseGetList = ( {
10
11
resource = 'posts' ,
@@ -343,4 +344,35 @@ describe('useGetList', () => {
343
344
queryClient . getQueryData ( [ 'posts' , 'getOne' , { id : '1' } ] )
344
345
) . toEqual ( { id : 1 , title : 'live' } ) ;
345
346
} ) ;
347
+
348
+ it ( 'should not fail when the query is disabled and the cache gets updated by another query' , async ( ) => {
349
+ const callback : any = jest . fn ( ) ;
350
+ const onSuccess = jest . fn ( ) ;
351
+ const queryClient = new QueryClient ( ) ;
352
+ const dataProvider = ( {
353
+ getList : jest . fn ( ( ) =>
354
+ Promise . resolve ( { data : [ { id : 1 , title : 'live' } ] , total : 1 } )
355
+ ) ,
356
+ } as unknown ) as DataProvider ;
357
+ render (
358
+ < CoreAdminContext
359
+ queryClient = { queryClient }
360
+ dataProvider = { dataProvider }
361
+ >
362
+ < UseGetList
363
+ options = { { enabled : false , onSuccess } }
364
+ callback = { callback }
365
+ />
366
+ </ CoreAdminContext >
367
+ ) ;
368
+ await waitFor ( ( ) => {
369
+ expect ( callback ) . toHaveBeenCalled ( ) ;
370
+ } ) ;
371
+ // Simulate the side-effect of e.g. a call to delete
372
+ queryClient . setQueriesData ( [ 'posts' , 'getList' ] , res => res ) ;
373
+ // If we get this far without an error being thrown, the test passes
374
+ await waitFor ( ( ) => {
375
+ expect ( onSuccess ) . toHaveBeenCalled ( ) ;
376
+ } ) ;
377
+ } ) ;
346
378
} ) ;
0 commit comments