Skip to content

Commit 01616c6

Browse files
authored
test(query-core/queryObserver): add test for 'refetchInterval' as a function called with the query (#10901)
1 parent 84cbbdb commit 01616c6

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,22 @@ describe('queryObserver', () => {
765765
unsubscribe()
766766
})
767767

768+
it('should call refetchInterval with the query when it is a function', async () => {
769+
const key = queryKey()
770+
const refetchInterval = vi.fn(() => 10)
771+
const observer = new QueryObserver(queryClient, {
772+
queryKey: key,
773+
queryFn: () => sleep(10).then(() => 'data'),
774+
refetchInterval,
775+
})
776+
const unsubscribe = observer.subscribe(() => undefined)
777+
await vi.advanceTimersByTimeAsync(10)
778+
expect(refetchInterval).toHaveBeenCalledWith(
779+
queryClient.getQueryCache().find({ queryKey: key }),
780+
)
781+
unsubscribe()
782+
})
783+
768784
it('should use placeholderData as non-cache data when pending a query with no data', async () => {
769785
const key = queryKey()
770786
const observer = new QueryObserver(queryClient, {

0 commit comments

Comments
 (0)