From 98126991508769ebad886a15c0e5d0845b4940b5 Mon Sep 17 00:00:00 2001 From: Dominik Dorfmeister Date: Fri, 11 Oct 2024 20:17:36 +0200 Subject: [PATCH] chore: try to stabilize a flaky test --- .../src/__tests__/useMutationState.test.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/react-query/src/__tests__/useMutationState.test.tsx b/packages/react-query/src/__tests__/useMutationState.test.tsx index 24a50de691..32fb793cc0 100644 --- a/packages/react-query/src/__tests__/useMutationState.test.tsx +++ b/packages/react-query/src/__tests__/useMutationState.test.tsx @@ -7,7 +7,6 @@ import { createQueryClient, doNotExecute, renderWithClient, - setActTimeout, sleep, } from './utils' import type { MutationState, MutationStatus } from '@tanstack/query-core' @@ -27,26 +26,24 @@ describe('useIsMutating', () => { const { mutate: mutate1 } = useMutation({ mutationKey: ['mutation1'], mutationFn: async () => { - await sleep(150) + await sleep(50) return 'data' }, }) const { mutate: mutate2 } = useMutation({ mutationKey: ['mutation2'], mutationFn: async () => { - await sleep(50) + await sleep(10) return 'data' }, }) - React.useEffect(() => { - mutate1() - setActTimeout(() => { - mutate2() - }, 50) - }, [mutate1, mutate2]) - - return null + return ( +
+ + +
+ ) } function Page() { @@ -58,7 +55,10 @@ describe('useIsMutating', () => { ) } - renderWithClient(queryClient, ) + const rendered = renderWithClient(queryClient, ) + fireEvent.click(rendered.getByRole('button', { name: /mutate1/i })) + await sleep(10) + fireEvent.click(rendered.getByRole('button', { name: /mutate2/i })) await waitFor(() => expect(isMutatingArray).toEqual([0, 1, 2, 1, 0])) })