@tanstack/query-core 5.27.2 → 5.27.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -465,13 +465,12 @@ describe('queryObserver', () => {
465
465
  })
466
466
  observer.setOptions({ queryKey: key, enabled: false, staleTime: 10 })
467
467
  await queryClient.fetchQuery({ queryKey: key, queryFn })
468
- await sleep(100)
468
+ await sleep(20)
469
469
  unsubscribe()
470
470
  expect(queryFn).toHaveBeenCalledTimes(1)
471
- expect(results.length).toBe(3)
472
- expect(results[0]).toMatchObject({ isStale: true })
473
- expect(results[1]).toMatchObject({ isStale: false })
474
- expect(results[2]).toMatchObject({ isStale: true })
471
+ expect(results.length).toBe(2)
472
+ expect(results[0]).toMatchObject({ isStale: false, data: undefined })
473
+ expect(results[1]).toMatchObject({ isStale: false, data: 'data' })
475
474
  })
476
475
 
477
476
  test('should be able to handle multiple subscribers', async () => {
@@ -885,11 +884,12 @@ describe('queryObserver', () => {
885
884
 
886
885
  const observer = new QueryObserver(queryClient, {
887
886
  queryKey: key,
887
+ enabled: false,
888
888
  })
889
889
 
890
890
  const spy = vi.fn()
891
891
  const unsubscribe = queryClient.getQueryCache().subscribe(spy)
892
- observer.setOptions({ queryKey: key, enabled: false })
892
+ observer.setOptions({ queryKey: key, enabled: false, refetchInterval: 10 })
893
893
 
894
894
  expect(spy).toHaveBeenCalledTimes(1)
895
895
  expect(spy).toHaveBeenCalledWith(
@@ -898,4 +898,16 @@ describe('queryObserver', () => {
898
898
 
899
899
  unsubscribe()
900
900
  })
901
+
902
+ test('disabled observers should not be stale', async () => {
903
+ const key = queryKey()
904
+
905
+ const observer = new QueryObserver(queryClient, {
906
+ queryKey: key,
907
+ enabled: false,
908
+ })
909
+
910
+ const result = observer.getCurrentResult()
911
+ expect(result.isStale).toBe(false)
912
+ })
901
913
  })