@@ -3,8 +3,8 @@ import { newPromise, newSymbol } from "../__testfixtures__";
3
3
import { useGet } from "./useGet" ;
4
4
import { it , expect , beforeEach , describe , vi } from "vitest" ;
5
5
6
- const result1 = newSymbol ( "Result 1" ) ;
7
- const result2 = newSymbol ( "Result 2" ) ;
6
+ const result1 = newSymbol < string > ( "Result 1" ) ;
7
+ const result2 = newSymbol < string > ( "Result 2" ) ;
8
8
const error = newSymbol ( "Error" ) ;
9
9
10
10
const refA1 = newSymbol ( "Ref A1" ) ;
@@ -126,3 +126,24 @@ describe("when ref changes", () => {
126
126
} ) ;
127
127
} ) ;
128
128
} ) ;
129
+
130
+ it ( "refetches if `getData` changes" , async ( ) => {
131
+ const getData1 = vi . fn ( ) . mockResolvedValue ( result1 ) ;
132
+ const getData2 = vi . fn ( ) . mockResolvedValue ( result2 ) ;
133
+
134
+ const { result, rerender } = renderHook ( ( { getData } ) => useGet ( refA1 , getData , isEqual ) , {
135
+ initialProps : { getData : getData1 } ,
136
+ } ) ;
137
+
138
+ await waitFor ( ( ) => {
139
+ expect ( result . current ) . toStrictEqual ( [ result1 , false , undefined ] ) ;
140
+ } ) ;
141
+ expect ( getData1 ) . toHaveBeenCalledTimes ( 1 ) ;
142
+
143
+ rerender ( { getData : getData2 } ) ;
144
+
145
+ await waitFor ( ( ) => {
146
+ expect ( result . current ) . toStrictEqual ( [ result2 , false , undefined ] ) ;
147
+ } ) ;
148
+ expect ( getData2 ) . toHaveBeenCalledTimes ( 1 ) ;
149
+ } ) ;
0 commit comments