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

inject-is-fetching.test.ts

37 lines888 Bytes

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