Skip to content

Commit fc9e160

Browse files
committed
Merge branch 'main' into test/query-core-query-observer-notify-on-change-props-function
# Conflicts: # packages/query-core/src/__tests__/queryObserver.test.tsx
2 parents 03f6585 + 01616c6 commit fc9e160

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,40 @@ 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+
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+
750784
it('should notify listeners when notifyOnChangeProps is a function returning props that changed', async () => {
751785
const key = queryKey()
752786

0 commit comments

Comments
 (0)