Skip to content

Commit 72a15ae

Browse files
authored
test(angular-query-experimental/injectMutation): switch 'pending' test to '@component' + 'render' pattern (TanStack#10590)
1 parent e69e5d2 commit 72a15ae

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,34 @@ describe('injectMutation', () => {
5050
it('should change state after invoking mutate', async () => {
5151
const result = 'Mock data'
5252

53-
const mutation = TestBed.runInInjectionContext(() => {
54-
return injectMutation(() => ({
53+
@Component({
54+
template: `
55+
<div>isIdle: {{ mutation.isIdle() }}</div>
56+
<div>isPending: {{ mutation.isPending() }}</div>
57+
<div>isError: {{ mutation.isError() }}</div>
58+
<div>isSuccess: {{ mutation.isSuccess() }}</div>
59+
<div>data: {{ mutation.data() ?? 'none' }}</div>
60+
<div>error: {{ mutation.error()?.message ?? 'none' }}</div>
61+
`,
62+
})
63+
class Page {
64+
readonly mutation = injectMutation(() => ({
5565
mutationFn: (params: string) => sleep(10).then(() => params),
5666
}))
57-
})
67+
}
5868

59-
TestBed.tick()
69+
const rendered = await render(Page)
6070

61-
mutation.mutate(result)
71+
rendered.fixture.componentInstance.mutation.mutate(result)
6272
await vi.advanceTimersByTimeAsync(0)
73+
rendered.fixture.detectChanges()
6374

64-
expectSignals(mutation, {
65-
isIdle: false,
66-
isPending: true,
67-
isError: false,
68-
isSuccess: false,
69-
data: undefined,
70-
error: null,
71-
})
75+
expect(rendered.getByText('isIdle: false')).toBeInTheDocument()
76+
expect(rendered.getByText('isPending: true')).toBeInTheDocument()
77+
expect(rendered.getByText('isError: false')).toBeInTheDocument()
78+
expect(rendered.getByText('isSuccess: false')).toBeInTheDocument()
79+
expect(rendered.getByText('data: none')).toBeInTheDocument()
80+
expect(rendered.getByText('error: none')).toBeInTheDocument()
7281
})
7382

7483
it('should return error when request fails', async () => {

0 commit comments

Comments
 (0)