Skip to content
Source
Sign inSign up
TanStack/query

test(angular-query/inject-query): restore test for 'enabled' signal turning false and back to true #12731

Opensukvvon(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12731/headopened View on GitHub

Showing 1 changed file with 29 additions and 0 deletions.

x
0 of 1 viewed, 1 left
29 additions and 0 deletionspackages/angular-query/src/__tests__/inject-query.test.tsModified
View file
@@ -600,6 +600,35 @@
expect(query.status()).toBe('success')
​
+ it('should not fetch while the enabled signal is false, and fetch again once it is truthy', async () => {
+ const key = createKey()
+ const queryFn = vi.fn<() => Promise<string>>(() =>
+ sleep(10).then(() => 'Some data'),
+ )
+ const filter = signal('a')
+​
+ const query = TestBed.runInInjectionContext(() =>
+ injectQuery(() => ({
+ queryKey: [...key, filter()],
+ queryFn,
+ enabled: !!filter(),
+ })),
+ )
+​
+ await vi.advanceTimersByTimeAsync(10)
+ expect(queryFn).toHaveBeenCalledTimes(1)
+ expect(query.status()).toBe('success')
+​
+ filter.set('')
+ await vi.advanceTimersByTimeAsync(10)
+ expect(queryFn).toHaveBeenCalledTimes(1)
+ expect(query.isFetching()).toBe(false)
+​
+ filter.set('b')
+ await vi.advanceTimersByTimeAsync(10)