Skip to content

Commit 9dcd588

Browse files
sukvvonmanudeli
andauthored
test(angular-query-experimental/inject-is-mutating): separate 'injectionContext' from testing, and add more 'expect' (#9425)
Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
1 parent 35d5d55 commit 9dcd588

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,26 @@ describe('injectIsMutating', () => {
2828
vi.useRealTimers()
2929
})
3030

31-
test('should properly return isMutating state', () => {
32-
TestBed.runInInjectionContext(() => {
33-
const isMutating = injectIsMutating()
34-
const mutation = injectMutation(() => ({
31+
test('should properly return isMutating state', async () => {
32+
const [mutation, isMutating] = TestBed.runInInjectionContext(() => [
33+
injectMutation(() => ({
3534
mutationKey: ['isMutating1'],
36-
mutationFn: (params: { par1: string }) => sleep(0).then(() => params),
37-
}))
35+
mutationFn: (params: { par1: string }) => sleep(10).then(() => params),
36+
})),
37+
injectIsMutating(),
38+
])
3839

39-
expect(isMutating()).toBe(0)
40+
expect(isMutating()).toBe(0)
4041

41-
mutation.mutate({
42-
par1: 'par1',
43-
})
44-
45-
vi.advanceTimersByTime(1)
46-
47-
expect(isMutating()).toBe(1)
42+
mutation.mutate({
43+
par1: 'par1',
4844
})
45+
46+
expect(isMutating()).toBe(0)
47+
await vi.advanceTimersByTimeAsync(0)
48+
expect(isMutating()).toBe(1)
49+
await vi.advanceTimersByTimeAsync(11)
50+
expect(isMutating()).toBe(0)
4951
})
5052

5153
describe('injection context', () => {

0 commit comments

Comments
 (0)