@tanstack/query-core 4.3.4 → 4.3.6
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.
- package/build/lib/index.d.ts +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/tests/focusManager.test.d.ts +1 -0
- package/build/lib/tests/hydration.test.d.ts +1 -0
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts +1 -0
- package/build/lib/tests/infiniteQueryObserver.test.d.ts +1 -0
- package/build/lib/tests/mutationCache.test.d.ts +1 -0
- package/build/lib/tests/mutationObserver.test.d.ts +1 -0
- package/build/lib/tests/mutations.test.d.ts +1 -0
- package/build/lib/tests/notifyManager.test.d.ts +1 -0
- package/build/lib/tests/onlineManager.test.d.ts +1 -0
- package/build/lib/tests/queriesObserver.test.d.ts +1 -0
- package/build/lib/tests/query.test.d.ts +1 -0
- package/build/lib/tests/queryCache.test.d.ts +1 -0
- package/build/lib/tests/queryClient.test.d.ts +1 -0
- package/build/lib/tests/queryObserver.test.d.ts +1 -0
- package/build/lib/tests/utils.d.ts +24 -0
- package/build/lib/tests/utils.test.d.ts +1 -0
- package/build/umd/index.development.js +1 -0
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/tests/focusManager.test.tsx +1 -1
- package/src/tests/hydration.test.tsx +1 -1
- package/src/tests/infiniteQueryBehavior.test.tsx +1 -1
- package/src/tests/infiniteQueryObserver.test.tsx +1 -1
- package/src/tests/mutationCache.test.tsx +1 -6
- package/src/tests/mutationObserver.test.tsx +1 -1
- package/src/tests/mutations.test.tsx +1 -6
- package/src/tests/notifyManager.test.tsx +1 -1
- package/src/tests/onlineManager.test.tsx +1 -1
- package/src/tests/queriesObserver.test.tsx +1 -6
- package/src/tests/query.test.tsx +1 -1
- package/src/tests/queryCache.test.tsx +1 -1
- package/src/tests/queryClient.test.tsx +1 -6
- package/src/tests/queryObserver.test.tsx +1 -1
- package/src/tests/utils.test.tsx +1 -1
- package/src/tests/utils.ts +78 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
InfiniteQueryObserver,
|
|
5
5
|
InfiniteQueryObserverResult,
|
|
6
6
|
} from '@tanstack/query-core'
|
|
7
|
-
import { createQueryClient, queryKey } from '
|
|
7
|
+
import { createQueryClient, queryKey } from './utils'
|
|
8
8
|
|
|
9
9
|
describe('InfiniteQueryBehavior', () => {
|
|
10
10
|
let queryClient: QueryClient
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
-
import {
|
|
3
|
-
queryKey,
|
|
4
|
-
sleep,
|
|
5
|
-
executeMutation,
|
|
6
|
-
createQueryClient,
|
|
7
|
-
} from '../../../../tests/utils'
|
|
2
|
+
import { queryKey, sleep, executeMutation, createQueryClient } from './utils'
|
|
8
3
|
import { MutationCache, MutationObserver } from '..'
|
|
9
4
|
|
|
10
5
|
describe('mutationCache', () => {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { QueryClient } from '..'
|
|
2
|
-
import {
|
|
3
|
-
createQueryClient,
|
|
4
|
-
executeMutation,
|
|
5
|
-
queryKey,
|
|
6
|
-
sleep,
|
|
7
|
-
} from '../../../../tests/utils'
|
|
2
|
+
import { createQueryClient, executeMutation, queryKey, sleep } from './utils'
|
|
8
3
|
import { MutationState } from '../mutation'
|
|
9
4
|
import { MutationObserver } from '../mutationObserver'
|
|
10
5
|
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
|
-
import {
|
|
3
|
-
sleep,
|
|
4
|
-
queryKey,
|
|
5
|
-
createQueryClient,
|
|
6
|
-
mockLogger,
|
|
7
|
-
} from '../../../../tests/utils'
|
|
2
|
+
import { sleep, queryKey, createQueryClient, mockLogger } from './utils'
|
|
8
3
|
import {
|
|
9
4
|
QueryClient,
|
|
10
5
|
QueriesObserver,
|
package/src/tests/query.test.tsx
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
sleep,
|
|
6
|
-
queryKey,
|
|
7
|
-
mockLogger,
|
|
8
|
-
createQueryClient,
|
|
9
|
-
} from '../../../../tests/utils'
|
|
4
|
+
import { sleep, queryKey, mockLogger, createQueryClient } from './utils'
|
|
10
5
|
import {
|
|
11
6
|
InfiniteQueryObserver,
|
|
12
7
|
QueryCache,
|
package/src/tests/utils.test.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isPlainArray,
|
|
10
10
|
} from '../utils'
|
|
11
11
|
import { Mutation } from '../mutation'
|
|
12
|
-
import { createQueryClient } from '
|
|
12
|
+
import { createQueryClient } from './utils'
|
|
13
13
|
|
|
14
14
|
describe('core/utils', () => {
|
|
15
15
|
describe('isPlainObject', () => {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { act } from '@testing-library/react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
MutationOptions,
|
|
5
|
+
QueryClient,
|
|
6
|
+
QueryClientConfig,
|
|
7
|
+
} from '@tanstack/query-core'
|
|
8
|
+
import * as utils from '../utils'
|
|
9
|
+
|
|
10
|
+
export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
11
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
|
12
|
+
return new QueryClient({ logger: mockLogger, ...config })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function mockVisibilityState(value: DocumentVisibilityState) {
|
|
16
|
+
return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function mockNavigatorOnLine(value: boolean) {
|
|
20
|
+
return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const mockLogger = {
|
|
24
|
+
log: jest.fn(),
|
|
25
|
+
warn: jest.fn(),
|
|
26
|
+
error: jest.fn(),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let queryKeyCount = 0
|
|
30
|
+
export function queryKey(): Array<string> {
|
|
31
|
+
queryKeyCount++
|
|
32
|
+
return [`query_${queryKeyCount}`]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function sleep(timeout: number): Promise<void> {
|
|
36
|
+
return new Promise((resolve, _reject) => {
|
|
37
|
+
setTimeout(resolve, timeout)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function setActTimeout(fn: () => void, ms?: number) {
|
|
42
|
+
return setTimeout(() => {
|
|
43
|
+
act(() => {
|
|
44
|
+
fn()
|
|
45
|
+
})
|
|
46
|
+
}, ms)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Assert the parameter is of a specific type.
|
|
51
|
+
*/
|
|
52
|
+
export const expectType = <T>(_: T): void => undefined
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Assert the parameter is not typed as `any`
|
|
56
|
+
*/
|
|
57
|
+
export const expectTypeNotAny = <T>(_: 0 extends 1 & T ? never : T): void =>
|
|
58
|
+
undefined
|
|
59
|
+
|
|
60
|
+
export const executeMutation = (
|
|
61
|
+
queryClient: QueryClient,
|
|
62
|
+
options: MutationOptions<any, any, any, any>,
|
|
63
|
+
): Promise<unknown> => {
|
|
64
|
+
return queryClient.getMutationCache().build(queryClient, options).execute()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// This monkey-patches the isServer-value from utils,
|
|
68
|
+
// so that we can pretend to be in a server environment
|
|
69
|
+
export function setIsServer(isServer: boolean) {
|
|
70
|
+
const original = utils.isServer
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
utils.isServer = isServer
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
utils.isServer = original
|
|
77
|
+
}
|
|
78
|
+
}
|