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

inject-is-mutating.test.ts

41 lines946 Bytes

1import { beforeEach, describe } from 'vitest'
2import { TestBed, fakeAsync, tick } from '@angular/core/testing'
3import {
4 QueryClient,
5 injectIsMutating,
6 injectMutation,
7 provideAngularQuery,
8} from '..'
9import { successMutator } from './test-utils'
10​
11describe('injectIsMutating', () => {
12 let queryClient: QueryClient
13​
14 beforeEach(() => {
15 queryClient = new QueryClient()
16​
17 TestBed.configureTestingModule({
18 providers: [provideAngularQuery(queryClient)],
19 })
20 })
21​
22 test('should properly return isMutating state', fakeAsync(() => {
23 TestBed.runInInjectionContext(() => {
24 const isMutating = injectIsMutating()
25 const mutation = injectMutation(() => ({
26 mutationKey: ['isMutating1'],
27 mutationFn: successMutator<{ par1: string }>,
28 }))
29​
30 expect(isMutating()).toBe(0)
31​
32 mutation.mutate({
33 par1: 'par1',
34 })
35​
36 tick()
37​
38 expect(isMutating()).toBe(1)
39 })
40 }))
41})