Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

inject-is-fetching.test.ts

35 lines999 Bytes

1import { TestBed, fakeAsync, flush, tick } from '@angular/core/testing'
2import { QueryClient } from '@tanstack/query-core'
3import { beforeEach, describe, expect } from 'vitest'
4import { injectIsFetching } from '../inject-is-fetching'
5import { injectQuery } from '../inject-query'
6import { provideAngularQuery } from '../providers'
7import { delayedFetcher } from './test-utils'
8​
9describe('injectIsFetching', () => {
10 let queryClient: QueryClient
11​
12 beforeEach(() => {
13 queryClient = new QueryClient()
14​
15 TestBed.configureTestingModule({
16 providers: [provideAngularQuery(queryClient)],
17 })
18 })
19​
20 test('Returns number of fetching queries', fakeAsync(() => {
21 const isFetching = TestBed.runInInjectionContext(() => {
22 injectQuery(() => ({
23 queryKey: ['isFetching1'],
24 queryFn: delayedFetcher(100),
25 }))
26 return injectIsFetching()
27 })
28​
29 tick()
30​
31 expect(isFetching()).toStrictEqual(1)
32 flush()
33 expect(isFetching()).toStrictEqual(0)
34 }))
35})