@tanstack/solid-query 5.0.0-alpha.4 → 5.0.0-alpha.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/source/__tests__/QueryClientProvider.test.jsx +2 -1
- package/build/source/__tests__/createInfiniteQuery.test.jsx +11 -10
- package/build/source/__tests__/createMutation.test.jsx +19 -18
- package/build/source/__tests__/createQueries.test.jsx +2 -17
- package/build/source/__tests__/createQuery.test.jsx +26 -25
- package/build/source/__tests__/suspense.test.jsx +6 -5
- package/build/source/__tests__/useIsMutating.test.jsx +23 -22
- package/build/source/__tests__/utils.jsx +3 -2
- package/build/types/__tests__/utils.d.ts +2 -3
- package/build/umd/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/createInfiniteQuery.test.tsx +20 -18
- package/src/__tests__/createMutation.test.tsx +19 -18
- package/src/__tests__/createQueries.test.tsx +2 -26
- package/src/__tests__/createQuery.test.tsx +27 -25
- package/src/__tests__/suspense.test.tsx +6 -5
- package/src/__tests__/useIsMutating.test.tsx +29 -33
- package/src/__tests__/utils.tsx +3 -2
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
QueryClientProvider,
|
|
21
21
|
} from '..'
|
|
22
22
|
import { createQueryClient, queryKey, sleep } from './utils'
|
|
23
|
+
import { vi } from 'vitest'
|
|
23
24
|
|
|
24
25
|
describe("useQuery's in Suspense mode", () => {
|
|
25
26
|
const queryCache = new QueryCache()
|
|
@@ -142,7 +143,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
142
143
|
it('should not call the queryFn twice when used in Suspense mode', async () => {
|
|
143
144
|
const key = queryKey()
|
|
144
145
|
|
|
145
|
-
const queryFn =
|
|
146
|
+
const queryFn = vi.fn<unknown[], string>()
|
|
146
147
|
queryFn.mockImplementation(() => {
|
|
147
148
|
sleep(10)
|
|
148
149
|
return 'data'
|
|
@@ -219,7 +220,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
219
220
|
it('should call onSuccess on the first successful call', async () => {
|
|
220
221
|
const key = queryKey()
|
|
221
222
|
|
|
222
|
-
const successFn =
|
|
223
|
+
const successFn = vi.fn()
|
|
223
224
|
|
|
224
225
|
function Page() {
|
|
225
226
|
createQuery(() => ({
|
|
@@ -254,8 +255,8 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
254
255
|
it('should call every onSuccess handler within a suspense boundary', async () => {
|
|
255
256
|
const key = queryKey()
|
|
256
257
|
|
|
257
|
-
const successFn1 =
|
|
258
|
-
const successFn2 =
|
|
258
|
+
const successFn1 = vi.fn()
|
|
259
|
+
const successFn2 = vi.fn()
|
|
259
260
|
|
|
260
261
|
function FirstComponent() {
|
|
261
262
|
createQuery(() => ({
|
|
@@ -733,7 +734,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
733
734
|
it('should not call the queryFn when not enabled', async () => {
|
|
734
735
|
const key = queryKey()
|
|
735
736
|
|
|
736
|
-
const queryFn =
|
|
737
|
+
const queryFn = vi.fn<unknown[], Promise<string>>()
|
|
737
738
|
queryFn.mockImplementation(async () => {
|
|
738
739
|
await sleep(10)
|
|
739
740
|
return '23'
|
|
@@ -6,6 +6,7 @@ import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js'
|
|
|
6
6
|
import { render } from 'solid-testing-library'
|
|
7
7
|
import * as MutationCacheModule from '../../../query-core/src/mutationCache'
|
|
8
8
|
import { setActTimeout } from './utils'
|
|
9
|
+
import { vi } from 'vitest'
|
|
9
10
|
|
|
10
11
|
describe('useIsMutating', () => {
|
|
11
12
|
it('should return the number of fetching mutations', async () => {
|
|
@@ -157,6 +158,33 @@ describe('useIsMutating', () => {
|
|
|
157
158
|
await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]))
|
|
158
159
|
})
|
|
159
160
|
|
|
161
|
+
it('should use provided custom queryClient', async () => {
|
|
162
|
+
const queryClient = createQueryClient()
|
|
163
|
+
function Page() {
|
|
164
|
+
const isMutating = useIsMutating(undefined, () => queryClient)
|
|
165
|
+
const { mutate } = createMutation(
|
|
166
|
+
() => ({
|
|
167
|
+
mutationKey: ['mutation1'],
|
|
168
|
+
mutationFn: async () => {
|
|
169
|
+
await sleep(10)
|
|
170
|
+
return 'data'
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
() => queryClient,
|
|
174
|
+
)
|
|
175
|
+
createEffect(() => {
|
|
176
|
+
mutate()
|
|
177
|
+
})
|
|
178
|
+
return (
|
|
179
|
+
<div>
|
|
180
|
+
<div>mutating: {isMutating}</div>
|
|
181
|
+
</div>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
render(() => <Page></Page>)
|
|
185
|
+
await waitFor(() => screen.findByText('mutating: 1'))
|
|
186
|
+
})
|
|
187
|
+
|
|
160
188
|
it('should not change state if unmounted', async () => {
|
|
161
189
|
// We have to mock the MutationCache to not unsubscribe
|
|
162
190
|
// the listener when the component is unmounted
|
|
@@ -167,7 +195,7 @@ describe('useIsMutating', () => {
|
|
|
167
195
|
}
|
|
168
196
|
}
|
|
169
197
|
|
|
170
|
-
const MutationCacheSpy =
|
|
198
|
+
const MutationCacheSpy = vi
|
|
171
199
|
.spyOn(MutationCacheModule, 'MutationCache')
|
|
172
200
|
.mockImplementation((fn) => {
|
|
173
201
|
return new MutationCacheMock(fn)
|
|
@@ -217,36 +245,4 @@ describe('useIsMutating', () => {
|
|
|
217
245
|
await sleep(20)
|
|
218
246
|
MutationCacheSpy.mockRestore()
|
|
219
247
|
})
|
|
220
|
-
|
|
221
|
-
it('should use provided custom queryClient', async () => {
|
|
222
|
-
const queryClient = createQueryClient()
|
|
223
|
-
|
|
224
|
-
function Page() {
|
|
225
|
-
const isMutating = useIsMutating(undefined, () => queryClient)
|
|
226
|
-
const { mutate } = createMutation(
|
|
227
|
-
() => ({
|
|
228
|
-
mutationKey: ['mutation1'],
|
|
229
|
-
mutationFn: async () => {
|
|
230
|
-
await sleep(10)
|
|
231
|
-
return 'data'
|
|
232
|
-
},
|
|
233
|
-
}),
|
|
234
|
-
() => queryClient,
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
createEffect(() => {
|
|
238
|
-
mutate()
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
return (
|
|
242
|
-
<div>
|
|
243
|
-
<div>mutating: {isMutating}</div>
|
|
244
|
-
</div>
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
render(() => <Page></Page>)
|
|
249
|
-
|
|
250
|
-
await waitFor(() => screen.findByText('mutating: 1'))
|
|
251
|
-
})
|
|
252
248
|
})
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { QueryClientConfig } from '@tanstack/query-core'
|
|
|
2
2
|
import { QueryClient } from '@tanstack/query-core'
|
|
3
3
|
import type { ParentProps } from 'solid-js'
|
|
4
4
|
import { createEffect, createSignal, onCleanup, Show } from 'solid-js'
|
|
5
|
+
import { vi } from 'vitest'
|
|
5
6
|
|
|
6
7
|
let queryKeyCount = 0
|
|
7
8
|
export function queryKey(): Array<string> {
|
|
@@ -34,11 +35,11 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function mockVisibilityState(value: DocumentVisibilityState) {
|
|
37
|
-
return
|
|
38
|
+
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function mockNavigatorOnLine(value: boolean) {
|
|
41
|
-
return
|
|
42
|
+
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export function sleep(timeout: number): Promise<void> {
|