Skip to content

Commit cc97e9a

Browse files
authored
test(query-core/queriesObserver): add test for skipping 'trackResult' when 'notifyOnChangeProps' is set (#10512)
1 parent 658d32b commit cc97e9a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,30 @@ describe('queriesObserver', () => {
609609
expect(combined.count).toBe(1)
610610
})
611611

612+
test('should return observer result directly when notifyOnChangeProps is set', () => {
613+
const key = queryKey()
614+
const queryFn = vi.fn().mockReturnValue(1)
615+
616+
const observer = new QueriesObserver(queryClient, [
617+
{ queryKey: key, queryFn, notifyOnChangeProps: ['data'] },
618+
])
619+
620+
const trackResultSpy = vi.spyOn(QueryObserver.prototype, 'trackResult')
621+
622+
const [, , trackResult] = observer.getOptimisticResult(
623+
[{ queryKey: key, queryFn, notifyOnChangeProps: ['data'] }],
624+
undefined,
625+
)
626+
627+
const trackedResults = trackResult()
628+
629+
expect(trackedResults).toHaveLength(1)
630+
// trackResult should NOT be called when notifyOnChangeProps is set
631+
expect(trackResultSpy).not.toHaveBeenCalled()
632+
633+
trackResultSpy.mockRestore()
634+
})
635+
612636
test('should track properties on all observers when trackResult is called', () => {
613637
const key1 = queryKey()
614638
const key2 = queryKey()

0 commit comments

Comments
 (0)