@tanstack/query-core 5.0.0-alpha.84 → 5.0.0-alpha.86

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.
@@ -1,7 +1,6 @@
1
1
  import { waitFor } from '@testing-library/react'
2
2
  import '@testing-library/jest-dom'
3
3
 
4
- import { vi } from 'vitest'
5
4
  import {
6
5
  MutationObserver,
7
6
  QueryObserver,
@@ -11,7 +10,7 @@ import {
11
10
  import { noop } from '../utils'
12
11
  import {
13
12
  createQueryClient,
14
- mockNavigatorOnLine,
13
+ mockOnlineManagerIsOnline,
15
14
  queryKey,
16
15
  sleep,
17
16
  } from './utils'
@@ -1074,7 +1073,7 @@ describe('queryClient', () => {
1074
1073
  const key1 = queryKey()
1075
1074
  const queryFn1 = vi.fn<unknown[], string>().mockReturnValue('data1')
1076
1075
  await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
1077
- const onlineMock = mockNavigatorOnLine(false)
1076
+ const onlineMock = mockOnlineManagerIsOnline(false)
1078
1077
 
1079
1078
  await queryClient.refetchQueries({ queryKey: key1 })
1080
1079
 
@@ -1088,7 +1087,7 @@ describe('queryClient', () => {
1088
1087
  queryClient.setQueryDefaults(key1, { networkMode: 'always' })
1089
1088
  const queryFn1 = vi.fn<unknown[], string>().mockReturnValue('data1')
1090
1089
  await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
1091
- const onlineMock = mockNavigatorOnLine(false)
1090
+ const onlineMock = mockOnlineManagerIsOnline(false)
1092
1091
 
1093
1092
  await queryClient.refetchQueries({ queryKey: key1 })
1094
1093
 
@@ -1394,7 +1393,7 @@ describe('queryClient', () => {
1394
1393
  queryCacheOnFocusSpy.mockRestore()
1395
1394
  queryCacheOnOnlineSpy.mockRestore()
1396
1395
  mutationCacheResumePausedMutationsSpy.mockRestore()
1397
- onlineManager.setOnline(undefined)
1396
+ onlineManager.setOnline(true)
1398
1397
  })
1399
1398
 
1400
1399
  test('should resume paused mutations when coming online', async () => {
@@ -1424,7 +1423,7 @@ describe('queryClient', () => {
1424
1423
  expect(observer1.getCurrentResult().status).toBe('success')
1425
1424
  })
1426
1425
 
1427
- onlineManager.setOnline(undefined)
1426
+ onlineManager.setOnline(true)
1428
1427
  })
1429
1428
 
1430
1429
  test('should resume paused mutations one after the other when invoked manually at the same time', async () => {
@@ -1459,7 +1458,7 @@ describe('queryClient', () => {
1459
1458
  expect(observer2.getCurrentResult().isPaused).toBeTruthy()
1460
1459
  })
1461
1460
 
1462
- onlineManager.setOnline(undefined)
1461
+ onlineManager.setOnline(true)
1463
1462
  void queryClient.resumePausedMutations()
1464
1463
  await sleep(5)
1465
1464
  await queryClient.resumePausedMutations()
@@ -1491,6 +1490,7 @@ describe('queryClient', () => {
1491
1490
  'resumePausedMutations',
1492
1491
  )
1493
1492
 
1493
+ onlineManager.setOnline(false)
1494
1494
  onlineManager.setOnline(true)
1495
1495
  expect(queryCacheOnOnlineSpy).toHaveBeenCalledTimes(1)
1496
1496
  expect(mutationCacheResumePausedMutationsSpy).toHaveBeenCalledTimes(1)
@@ -1503,7 +1503,7 @@ describe('queryClient', () => {
1503
1503
  queryCacheOnOnlineSpy.mockRestore()
1504
1504
  mutationCacheResumePausedMutationsSpy.mockRestore()
1505
1505
  focusManager.setFocused(undefined)
1506
- onlineManager.setOnline(undefined)
1506
+ onlineManager.setOnline(true)
1507
1507
  })
1508
1508
 
1509
1509
  test('should not notify queryCache and mutationCache after multiple mounts/unmounts', async () => {
@@ -1538,7 +1538,7 @@ describe('queryClient', () => {
1538
1538
  queryCacheOnOnlineSpy.mockRestore()
1539
1539
  mutationCacheResumePausedMutationsSpy.mockRestore()
1540
1540
  focusManager.setFocused(undefined)
1541
- onlineManager.setOnline(undefined)
1541
+ onlineManager.setOnline(true)
1542
1542
  })
1543
1543
  })
1544
1544
 
@@ -1,20 +1,24 @@
1
1
  import { act } from '@testing-library/react'
2
2
  import { vi } from 'vitest'
3
-
4
- import { QueryClient } from '..'
3
+ import { QueryClient, onlineManager } from '..'
5
4
  import * as utils from '../utils'
5
+ import type { SpyInstance } from 'vitest'
6
6
  import type { MutationOptions, QueryClientConfig } from '..'
7
7
 
8
8
  export function createQueryClient(config?: QueryClientConfig): QueryClient {
9
9
  return new QueryClient(config)
10
10
  }
11
11
 
12
- export function mockVisibilityState(value: DocumentVisibilityState) {
12
+ export function mockVisibilityState(
13
+ value: DocumentVisibilityState,
14
+ ): SpyInstance<[], DocumentVisibilityState> {
13
15
  return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
14
16
  }
15
17
 
16
- export function mockNavigatorOnLine(value: boolean) {
17
- return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
18
+ export function mockOnlineManagerIsOnline(
19
+ value: boolean,
20
+ ): SpyInstance<[], boolean> {
21
+ return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
18
22
  }
19
23
 
20
24
  let queryKeyCount = 0