From 78fdbae81123489f7be9ad7c99913c6e4f11b0bd Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sun, 25 Oct 2026 13:29:02 +0900 Subject: [PATCH] test(preact-query/useMutation): wait for the mutation to settle after unmount and assert that no error is logged --- packages/preact-query/src/__tests__/useMutation.test.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/preact-query/src/__tests__/useMutation.test.tsx b/packages/preact-query/src/__tests__/useMutation.test.tsx index b9014e6f629..5c9bc4aa914 100644 --- a/packages/preact-query/src/__tests__/useMutation.test.tsx +++ b/packages/preact-query/src/__tests__/useMutation.test.tsx @@ -1273,8 +1273,10 @@ describe('useMutation', () => { }) }) - // oxlint-disable-next-line vitest/expect-expect - it('should not change state if unmounted', () => { + it('should not change state if unmounted', async () => { + const consoleErrorMock = vi + .spyOn(console, 'error') + .mockReturnValue(undefined) function Mutates() { const { mutate } = useMutation({ mutationFn: () => sleep(10) }) return @@ -1292,6 +1294,8 @@ describe('useMutation', () => { const { getByText } = renderWithClient(queryClient, ) fireEvent.click(getByText('mutate')) fireEvent.click(getByText('unmount')) + await vi.advanceTimersByTimeAsync(10) + expect(consoleErrorMock).not.toHaveBeenCalled() }) it('should be able to throw an error when throwOnError is set to true', async () => {