Skip to content

Commit 762c163

Browse files
committed
test(query-core/query): retitle test to reflect actual coverage
The previous title ('fetch should start a new fetch when the previous retryer has rejected') claimed coverage of the `this.#retryer?.status() !== 'rejected'` branch in Query.fetch, but that guard sits behind `state.fetchStatus !== 'idle'`. Once the prior fetch has rejected and state.status becomes 'error', fetchStatus is already back to 'idle', so the first predicate short-circuits and the retryer.status() check is never evaluated. Removing the rejected-retryer exception would not flip this assertion. Rename and trim to what the test actually exercises: a rejected fetch followed by a successful refetch via Query.fetch. Per CodeRabbit review on PR #10529.
1 parent dc0cb95 commit 762c163

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

packages/query-core/src/__tests__/query.test.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ describe('query', () => {
849849
unsubscribe()
850850
})
851851

852-
it('fetch should start a new fetch when the previous retryer has rejected', async () => {
852+
it('fetch should refetch successfully after the previous fetch errored', async () => {
853853
const key = queryKey()
854854

855855
let shouldFail = true
@@ -860,19 +860,13 @@ describe('query', () => {
860860
return sleep(10).then(() => 'success')
861861
})
862862

863-
// Trigger a failing fetch so the query's retryer ends up rejected.
864863
queryClient.prefetchQuery({ queryKey: key, queryFn, retry: false })
865864
await vi.advanceTimersByTimeAsync(10)
866865

867866
const query = queryCache.find<string>({ queryKey: key })!
868867
expect(queryFn).toHaveBeenCalledTimes(1)
869868
expect(query.state.status).toBe('error')
870869

871-
// Flip the queryFn to succeed and invoke fetch directly on the Query.
872-
// The guard `this.#retryer?.status() !== 'rejected'` in Query.fetch must
873-
// let execution fall through to create a fresh retryer — otherwise the
874-
// call would early-return the previous (rejected) retryer's promise and
875-
// queryFn would never run again.
876870
shouldFail = false
877871
const refetchPromise = query.fetch({ queryKey: key, queryFn, retry: false })
878872
await vi.advanceTimersByTimeAsync(10)

0 commit comments

Comments
 (0)