Skip to content

Commit 84cbbdb

Browse files
authored
test(query-core/queryObserver): add test for 'refetchInterval' as a function refetching at the returned interval (#10899)
1 parent 413fdc5 commit 84cbbdb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,24 @@ describe('queryObserver', () => {
747747
expect(count).toBe(2)
748748
})
749749

750+
it('should refetch at the interval returned when refetchInterval is a function', async () => {
751+
const key = queryKey()
752+
let count = 0
753+
const observer = new QueryObserver(queryClient, {
754+
queryKey: key,
755+
queryFn: () => {
756+
count++
757+
return Promise.resolve('data')
758+
},
759+
refetchInterval: () => 10,
760+
})
761+
const unsubscribe = observer.subscribe(() => undefined)
762+
expect(count).toBe(1)
763+
await vi.advanceTimersByTimeAsync(10)
764+
expect(count).toBe(2)
765+
unsubscribe()
766+
})
767+
750768
it('should use placeholderData as non-cache data when pending a query with no data', async () => {
751769
const key = queryKey()
752770
const observer = new QueryObserver(queryClient, {

0 commit comments

Comments
 (0)