From da463cae2daa41cc10d66d5dc8673cac3a227963 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Wed, 10 Jun 2026 20:39:38 +0900 Subject: [PATCH 1/2] test(react-query/useQuery.promise): unskip 'cancelQueries' while suspending test by keeping 'queryFn' in-flight --- .../src/__tests__/useQuery.promise.test.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/react-query/src/__tests__/useQuery.promise.test.tsx b/packages/react-query/src/__tests__/useQuery.promise.test.tsx index e721c6a4d9c..ad571999331 100644 --- a/packages/react-query/src/__tests__/useQuery.promise.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.promise.test.tsx @@ -788,14 +788,15 @@ describe('useQuery().promise', { timeout: 10_000 }, () => { expect(queryFn).toHaveBeenCalledOnce() }) - it.skip('should stay pending when canceled with cancelQueries while suspending until refetched', async () => { + it('should stay pending when canceled with cancelQueries while suspending until refetched', async () => { const renderStream = createRenderStream({ snapshotDOM: true }) const key = queryKey() - let count = 0 - const queryFn = vi.fn().mockImplementation(async () => { - await sleep(10) - return 'test' + count++ - }) + // `sleep` is longer than usual on purpose: `takeRender` below advances the + // shared fake clock (`shouldAdvanceTime`) by ~35ms while awaiting the React + // commit, so the fetch must outlast that to stay in-flight when cancelled. + const queryFn = vi + .fn() + .mockImplementation(() => sleep(50).then(() => 'test')) const options = { queryKey: key, From 053a7afdc052790ee667c1c46294b8535e90d82a Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Wed, 10 Jun 2026 21:05:50 +0900 Subject: [PATCH 2/2] test(react-query/useQuery.promise): clarify why 'sleep' is extended in cancel-while-suspending test --- .../react-query/src/__tests__/useQuery.promise.test.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-query/src/__tests__/useQuery.promise.test.tsx b/packages/react-query/src/__tests__/useQuery.promise.test.tsx index ad571999331..9948c08cb25 100644 --- a/packages/react-query/src/__tests__/useQuery.promise.test.tsx +++ b/packages/react-query/src/__tests__/useQuery.promise.test.tsx @@ -791,9 +791,10 @@ describe('useQuery().promise', { timeout: 10_000 }, () => { it('should stay pending when canceled with cancelQueries while suspending until refetched', async () => { const renderStream = createRenderStream({ snapshotDOM: true }) const key = queryKey() - // `sleep` is longer than usual on purpose: `takeRender` below advances the - // shared fake clock (`shouldAdvanceTime`) by ~35ms while awaiting the React - // commit, so the fetch must outlast that to stay in-flight when cancelled. + // `sleep` is longer than usual on purpose: with `shouldAdvanceTime`, the + // real time spent rendering and awaiting `takeRender` (~40ms) is added to + // the fake clock, so a shorter fetch would resolve before `cancel` can take + // effect. A longer fetch keeps the query in-flight when it is cancelled. const queryFn = vi .fn() .mockImplementation(() => sleep(50).then(() => 'test'))