Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/query-core/src/__tests__/queryObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,52 @@ describe('queryObserver', () => {
unsubscribe()
})

it('should notify listeners when notifyOnChangeProps is a function returning props that changed', async () => {
const key = queryKey()

queryClient.setQueryData(key, 'data')

const observer = new QueryObserver(queryClient, {
queryKey: key,
queryFn: () => sleep(10).then(() => 'new data'),
staleTime: Infinity,
notifyOnChangeProps: () => ['data'],
})
const listener = vi.fn()

const unsubscribe = observer.subscribe(listener)
listener.mockClear()

observer.refetch()
await vi.advanceTimersByTimeAsync(10)
expect(listener).toHaveBeenCalledTimes(1)

unsubscribe()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})

it('should not notify listeners when notifyOnChangeProps is a function returning props that did not change', async () => {
const key = queryKey()

queryClient.setQueryData(key, 'data')

const observer = new QueryObserver(queryClient, {
queryKey: key,
queryFn: () => sleep(10).then(() => 'data'),
staleTime: Infinity,
notifyOnChangeProps: () => ['data'],
})
const listener = vi.fn()

const unsubscribe = observer.subscribe(listener)
listener.mockClear()

observer.refetch()
await vi.advanceTimersByTimeAsync(10)
expect(listener).not.toHaveBeenCalled()

unsubscribe()
})

it('should use placeholderData as non-cache data when pending a query with no data', async () => {
const key = queryKey()
const observer = new QueryObserver(queryClient, {
Expand Down
Loading