@@ -65,7 +65,7 @@ const api = createApi({
6565 } ,
6666 } ) ,
6767 } ) ,
68- getIncrementedAmount : build . query < any , void > ( {
68+ getIncrementedAmount : build . query < { amount : number } , void > ( {
6969 query : ( ) => ( {
7070 url : '' ,
7171 body : {
@@ -199,7 +199,7 @@ describe('hooks tests', () => {
199199 expect ( screen . getByTestId ( 'isLoading' ) . textContent ) . toBe ( 'false' )
200200 )
201201 // We call a refetch, should still be `false`
202- act ( ( ) => refetch ( ) )
202+ act ( ( ) => void refetch ( ) )
203203 await waitFor ( ( ) =>
204204 expect ( screen . getByTestId ( 'isFetching' ) . textContent ) . toBe ( 'true' )
205205 )
@@ -255,7 +255,7 @@ describe('hooks tests', () => {
255255 expect ( getRenderCount ( ) ) . toBe ( 5 )
256256
257257 // We call a refetch, should set `isFetching` to true, then false when complete/errored
258- act ( ( ) => refetchMe ( ) )
258+ act ( ( ) => void refetchMe ( ) )
259259 await waitFor ( ( ) => {
260260 expect ( screen . getByTestId ( 'isLoading' ) . textContent ) . toBe ( 'false' )
261261 expect ( screen . getByTestId ( 'isFetching' ) . textContent ) . toBe ( 'true' )
@@ -607,6 +607,28 @@ describe('hooks tests', () => {
607607 } )
608608 } )
609609 } )
610+
611+ test ( 'useQuery refetch method returns a promise that resolves with the result' , async ( ) => {
612+ const { result } = renderHook (
613+ ( ) => api . endpoints . getIncrementedAmount . useQuery ( ) ,
614+ {
615+ wrapper : storeRef . wrapper ,
616+ }
617+ )
618+
619+ await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) )
620+ const originalAmount = result . current . data ! . amount
621+
622+ const { refetch } = result . current
623+
624+ let resPromise : ReturnType < typeof refetch > = null as any
625+ await act ( async ( ) => {
626+ resPromise = refetch ( )
627+ } )
628+ expect ( resPromise ) . toBeInstanceOf ( Promise )
629+ const res = await resPromise
630+ expect ( res . data ! . amount ) . toBeGreaterThan ( originalAmount )
631+ } )
610632 } )
611633
612634 describe ( 'useLazyQuery' , ( ) => {
0 commit comments