Skip to content

Commit 98a5ba0

Browse files
committed
test(vue-query/mutationOptions): reorder getter tests to group by feature
1 parent aaeefae commit 98a5ba0

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

packages/vue-query/src/__tests__/mutationOptions.test.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ describe('mutationOptions', () => {
5454
expect(mutationOptions(getter)).toBe(getter)
5555
})
5656

57+
it('should work with getter passed to mutationOptions without mutationKey', async () => {
58+
const mutationOpts = mutationOptions(() => ({
59+
mutationFn: () => sleep(10).then(() => 'data'),
60+
}))
61+
62+
const { mutate, data } = useMutation(mutationOpts)
63+
64+
mutate()
65+
await vi.advanceTimersByTimeAsync(10)
66+
67+
expect(data.value).toEqual('data')
68+
})
69+
5770
it('should return the number of fetching mutations when used with useIsMutating (with mutationKey in mutationOptions)', async () => {
5871
const isMutatingArray: Array<number> = []
5972
const mutationOpts = mutationOptions({
@@ -225,6 +238,27 @@ describe('mutationOptions', () => {
225238
expect(isMutatingArray).toEqual([0, 1, 0])
226239
})
227240

241+
it('should work with getter passed to mutationOptions when used with useIsMutating', async () => {
242+
const keyRef = ref('isMutatingGetter')
243+
const mutationOpts = mutationOptions(() => ({
244+
mutationKey: [keyRef.value],
245+
mutationFn: () => sleep(10).then(() => 'data'),
246+
}))
247+
248+
const { mutate } = useMutation(mutationOpts)
249+
mutate()
250+
251+
const isMutating = useIsMutating({
252+
mutationKey: [keyRef.value],
253+
})
254+
255+
await vi.advanceTimersByTimeAsync(0)
256+
expect(isMutating.value).toEqual(1)
257+
258+
await vi.advanceTimersByTimeAsync(10)
259+
expect(isMutating.value).toEqual(0)
260+
})
261+
228262
it('should return the number of fetching mutations when used with queryClient.isMutating (with mutationKey in mutationOptions)', async () => {
229263
const isMutatingArray: Array<number> = []
230264
const queryClient = useQueryClient()
@@ -632,27 +666,6 @@ describe('mutationOptions', () => {
632666
expect(states.value).toEqual(['data1'])
633667
})
634668

635-
it('should work with getter passed to mutationOptions when used with useIsMutating', async () => {
636-
const keyRef = ref('isMutatingGetter')
637-
const mutationOpts = mutationOptions(() => ({
638-
mutationKey: [keyRef.value],
639-
mutationFn: () => sleep(10).then(() => 'data'),
640-
}))
641-
642-
const { mutate } = useMutation(mutationOpts)
643-
mutate()
644-
645-
const isMutating = useIsMutating({
646-
mutationKey: [keyRef.value],
647-
})
648-
649-
await vi.advanceTimersByTimeAsync(0)
650-
expect(isMutating.value).toEqual(1)
651-
652-
await vi.advanceTimersByTimeAsync(10)
653-
expect(isMutating.value).toEqual(0)
654-
})
655-
656669
it('should work with getter passed to mutationOptions when used with useMutationState', async () => {
657670
const keyRef = ref('useMutationStateGetter')
658671
const mutationOpts = mutationOptions(() => ({
@@ -672,19 +685,6 @@ describe('mutationOptions', () => {
672685
expect(states.value).toEqual(['foo'])
673686
})
674687

675-
it('should work with getter passed to mutationOptions without mutationKey', async () => {
676-
const mutationOpts = mutationOptions(() => ({
677-
mutationFn: () => sleep(10).then(() => 'data'),
678-
}))
679-
680-
const { mutate, data } = useMutation(mutationOpts)
681-
682-
mutate()
683-
await vi.advanceTimersByTimeAsync(10)
684-
685-
expect(data.value).toEqual('data')
686-
})
687-
688688
it('should return data in a shallow ref when shallow is true', async () => {
689689
const mutationOpts = mutationOptions({
690690
mutationKey: ['key'],

0 commit comments

Comments
 (0)