Skip to content

Commit 43049c5

Browse files
authored
test(react-query/useMutationState): clarify assertions and improve code formatting (#9611)
1 parent 7306474 commit 43049c5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ describe('useIsMutating', () => {
2020

2121
function IsMutating() {
2222
const isMutating = useIsMutating()
23+
2324
isMutatingArray.push(isMutating)
25+
2426
return null
2527
}
2628

@@ -52,6 +54,7 @@ describe('useIsMutating', () => {
5254
}
5355

5456
const rendered = renderWithClient(queryClient, <Page />)
57+
5558
fireEvent.click(rendered.getByRole('button', { name: /mutate1/i }))
5659
await vi.advanceTimersByTimeAsync(10)
5760
fireEvent.click(rendered.getByRole('button', { name: /mutate2/i }))
@@ -62,12 +65,14 @@ describe('useIsMutating', () => {
6265
// [ +0, 1, 2, 1, +0 ]
6366
// our batching strategy might yield different results
6467

65-
await vi.advanceTimersByTimeAsync(40)
68+
await vi.advanceTimersByTimeAsync(41)
6669
expect(isMutatingArray[0]).toEqual(0)
6770
expect(isMutatingArray[1]).toEqual(1)
6871
expect(isMutatingArray[2]).toEqual(2)
69-
await vi.advanceTimersByTimeAsync(1)
70-
expect(isMutatingArray[isMutatingArray.length - 1]).toEqual(0)
72+
expect(isMutatingArray[3]).toEqual(1)
73+
expect(isMutatingArray[4]).toEqual(0)
74+
75+
expect(isMutatingArray).toEqual([0, 1, 2, 1, 0])
7176
})
7277

7378
it('should filter correctly by mutationKey', async () => {
@@ -99,6 +104,7 @@ describe('useIsMutating', () => {
99104
}
100105

101106
renderWithClient(queryClient, <Page />)
107+
102108
await vi.advanceTimersByTimeAsync(101)
103109
expect(isMutatingArray).toEqual([0, 1, 0])
104110
})
@@ -135,6 +141,7 @@ describe('useIsMutating', () => {
135141
}
136142

137143
renderWithClient(queryClient, <Page />)
144+
138145
await vi.advanceTimersByTimeAsync(101)
139146
expect(isMutatingArray).toEqual([0, 1, 0])
140147
})
@@ -163,7 +170,7 @@ describe('useIsMutating', () => {
163170
)
164171
}
165172

166-
const rendered = render(<Page></Page>)
173+
const rendered = render(<Page />)
167174

168175
await vi.advanceTimersByTimeAsync(0)
169176
expect(rendered.getByText('mutating: 1')).toBeInTheDocument()
@@ -220,12 +227,11 @@ describe('useMutationState', () => {
220227

221228
const rendered = renderWithClient(queryClient, <Page />)
222229

223-
rendered.getByText('data: null')
230+
expect(rendered.getByText('data: null')).toBeInTheDocument()
224231

225232
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
226-
227233
await vi.advanceTimersByTimeAsync(151)
228-
rendered.getByText('data: data1')
234+
expect(rendered.getByText('data: data1')).toBeInTheDocument()
229235

230236
expect(variables).toEqual([[], [1], []])
231237
})

0 commit comments

Comments
 (0)