Skip to content

Commit bb257c2

Browse files
authored
test(solid-query/useMutationState): add test for default 'options' parameter coverage (#10148)
1 parent 984bfa6 commit bb257c2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/solid-query/src/__tests__/useMutationState.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,54 @@ describe('useMutationState', () => {
1818
vi.useRealTimers()
1919
})
2020

21+
it('should return all mutation states when called without options', async () => {
22+
const queryClient = new QueryClient()
23+
const mutationKey = ['mutation']
24+
25+
function States() {
26+
const mutationStates = useMutationState()
27+
28+
return <div>count: {mutationStates().length}</div>
29+
}
30+
31+
function Mutate() {
32+
const mutation = useMutation(() => ({
33+
mutationKey,
34+
mutationFn: (input: number) => sleep(150).then(() => 'data' + input),
35+
}))
36+
37+
return (
38+
<div>
39+
<button onClick={() => mutation.mutate(1)}>mutate</button>
40+
</div>
41+
)
42+
}
43+
44+
function Page() {
45+
return (
46+
<div>
47+
<States />
48+
<Mutate />
49+
</div>
50+
)
51+
}
52+
53+
const rendered = render(() => (
54+
<QueryClientProvider client={queryClient}>
55+
<Page />
56+
</QueryClientProvider>
57+
))
58+
59+
expect(rendered.getByText('count: 0')).toBeInTheDocument()
60+
61+
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
62+
await vi.advanceTimersByTimeAsync(0)
63+
expect(rendered.getByText('count: 1')).toBeInTheDocument()
64+
65+
await vi.advanceTimersByTimeAsync(150)
66+
expect(rendered.getByText('count: 1')).toBeInTheDocument()
67+
})
68+
2169
it('should return variables after calling mutate', async () => {
2270
const queryClient = new QueryClient()
2371
const variables: Array<Array<unknown>> = []

0 commit comments

Comments
 (0)