Skip to content

Commit ff2d13e

Browse files
committed
test(angular-query-experimental/injectIsMutating): add filter test by 'mutationKey'
1 parent 7a5b53c commit ff2d13e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ describe('injectIsMutating', () => {
6262
expect(rendered.getByText('mutating: 0')).toBeInTheDocument()
6363
})
6464

65+
it('should be able to filter by mutationKey', async () => {
66+
const key1 = queryKey()
67+
const key2 = queryKey()
68+
69+
@Component({
70+
template: `<div>mutating: {{ isMutating() }}</div>`,
71+
})
72+
class Page {
73+
readonly mutation1 = injectMutation(() => ({
74+
mutationKey: key1,
75+
mutationFn: () => sleep(10).then(() => 'data1'),
76+
}))
77+
readonly mutation2 = injectMutation(() => ({
78+
mutationKey: key2,
79+
mutationFn: () => sleep(100).then(() => 'data2'),
80+
}))
81+
readonly isMutating = injectIsMutating({ mutationKey: key1 })
82+
}
83+
84+
const rendered = await render(Page)
85+
86+
rendered.fixture.componentInstance.mutation1.mutate()
87+
rendered.fixture.componentInstance.mutation2.mutate()
88+
89+
await vi.advanceTimersByTimeAsync(0)
90+
rendered.fixture.detectChanges()
91+
expect(rendered.getByText('mutating: 1')).toBeInTheDocument()
92+
93+
await vi.advanceTimersByTimeAsync(11)
94+
rendered.fixture.detectChanges()
95+
expect(rendered.getByText('mutating: 0')).toBeInTheDocument()
96+
})
97+
6598
describe('injection context', () => {
6699
it('should throw NG0203 with descriptive error outside injection context', () => {
67100
expect(() => {

0 commit comments

Comments
 (0)