File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
packages/toolkit/src/query/tests Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ const api = createApi({
65
65
} ,
66
66
} ) ,
67
67
} ) ,
68
- getIncrementedAmount : build . query < any , void > ( {
68
+ getIncrementedAmount : build . query < { amount : number } , void > ( {
69
69
query : ( ) => ( {
70
70
url : '' ,
71
71
body : {
@@ -607,6 +607,28 @@ describe('hooks tests', () => {
607
607
} )
608
608
} )
609
609
} )
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
+ } )
610
632
} )
611
633
612
634
describe ( 'useLazyQuery' , ( ) => {
You can’t perform that action at this time.
0 commit comments