Skip to content

Commit

Permalink
test: don't use getAll
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo committed Mar 9, 2024
1 parent 245f3f9 commit 7014196
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/react-query/src/__tests__/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,13 @@ describe('useMutation', () => {

it('should be able to retry a mutation when online', async () => {
const onlineMock = mockOnlineManagerIsOnline(false)
const key = queryKey()

let count = 0

function Page() {
const state = useMutation({
mutationKey: key,
mutationFn: async (_text: string) => {
await sleep(10)
count++
Expand Down Expand Up @@ -614,8 +616,12 @@ describe('useMutation', () => {
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
await waitFor(() => rendered.getByText('isPaused: true'))

expect(queryClient.getMutationCache().getAll().length).toBe(1)
expect(queryClient.getMutationCache().getAll()[0]?.state).toMatchObject({
expect(
queryClient.getMutationCache().findAll({ mutationKey: key }).length,
).toBe(1)
expect(
queryClient.getMutationCache().findAll({ mutationKey: key })[0]?.state,
).toMatchObject({
status: 'pending',
isPaused: true,
failureCount: 1,
Expand All @@ -627,7 +633,9 @@ describe('useMutation', () => {

await waitFor(() => rendered.getByText('data: data'))

expect(queryClient.getMutationCache().getAll()[0]?.state).toMatchObject({
expect(
queryClient.getMutationCache().findAll({ mutationKey: key })[0]?.state,
).toMatchObject({
status: 'success',
isPaused: false,
failureCount: 0,
Expand Down

0 comments on commit 7014196

Please sign in to comment.