Open History to see the last commit
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})