File tree Expand file tree Collapse file tree
packages/query-devtools/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -561,6 +561,39 @@ describe('Devtools', () => {
561561 'pending' ,
562562 )
563563 } )
564+
565+ it ( 'should restore the previous query options when "Restore Loading" is clicked after "Trigger Loading"' , async ( ) => {
566+ const queryFn = vi . fn ( ( ) => Promise . resolve ( 'original' ) )
567+ queryClient . prefetchQuery ( {
568+ queryKey : [ 'action-restore-loading' ] ,
569+ queryFn,
570+ } )
571+ await vi . advanceTimersByTimeAsync ( 0 )
572+ expect ( queryFn ) . toHaveBeenCalledTimes ( 1 )
573+
574+ const rendered = renderDevtools ( { initialIsOpen : true } )
575+
576+ fireEvent . click (
577+ rendered . getByLabelText ( / Q u e r y k e y \[ " a c t i o n - r e s t o r e - l o a d i n g " \] / ) ,
578+ )
579+
580+ // First click puts the query into a pending state with `data: undefined`
581+ // and stashes the original options in `fetchMeta.__previousQueryOptions`.
582+ fireEvent . click ( rendered . getByText ( 'Trigger Loading' ) )
583+ expect (
584+ queryClient . getQueryState ( [ 'action-restore-loading' ] ) ?. status ,
585+ ) . toBe ( 'pending' )
586+
587+ // Second click runs `restoreQueryAfterLoadingOrError`, which cancels the
588+ // never-resolving fetch and refetches with the stashed options.
589+ fireEvent . click ( rendered . getByText ( 'Restore Loading' ) )
590+ await vi . advanceTimersByTimeAsync ( 0 )
591+
592+ expect ( queryFn ) . toHaveBeenCalledTimes ( 2 )
593+ expect ( queryClient . getQueryData ( [ 'action-restore-loading' ] ) ) . toBe (
594+ 'original' ,
595+ )
596+ } )
564597 } )
565598
566599 describe ( 'mutation details' , ( ) => {
You can’t perform that action at this time.
0 commit comments