|
1 | | -import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest' |
| 1 | +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' |
2 | 2 | import { onScopeDispose, reactive, ref } from 'vue-demi' |
3 | 3 | import { sleep } from '@tanstack/query-test-utils' |
4 | 4 | import { useMutation } from '../useMutation' |
5 | | -import { useIsMutating, useMutationState } from '../useMutationState' |
6 | | -import { useQueryClient } from '../useQueryClient' |
| 5 | +import { useIsMutating } from '../useMutationState' |
7 | 6 | import type { MockedFunction } from 'vitest' |
8 | 7 |
|
9 | 8 | vi.mock('../useQueryClient') |
@@ -110,75 +109,3 @@ describe('useIsMutating', () => { |
110 | 109 | expect(isMutating.value).toStrictEqual(1) |
111 | 110 | }) |
112 | 111 | }) |
113 | | - |
114 | | -describe('useMutationState', () => { |
115 | | - beforeEach(() => { |
116 | | - vi.useFakeTimers() |
117 | | - }) |
118 | | - |
119 | | - afterEach(() => { |
120 | | - vi.useRealTimers() |
121 | | - }) |
122 | | - |
123 | | - it('should return variables after calling mutate 1', () => { |
124 | | - const mutationKey = ['mutation'] |
125 | | - const variables = 'foo123' |
126 | | - |
127 | | - const { mutate } = useMutation({ |
128 | | - mutationKey: mutationKey, |
129 | | - mutationFn: (params: string) => sleep(0).then(() => params), |
130 | | - }) |
131 | | - |
132 | | - mutate(variables) |
133 | | - |
134 | | - const mutationState = useMutationState({ |
135 | | - filters: { mutationKey, status: 'pending' }, |
136 | | - select: (mutation) => mutation.state.variables, |
137 | | - }) |
138 | | - |
139 | | - expect(mutationState.value).toEqual([variables]) |
140 | | - }) |
141 | | - |
142 | | - it('should return variables after calling mutate 2', () => { |
143 | | - const queryClient = useQueryClient() |
144 | | - queryClient.clear() |
145 | | - const mutationKey = ['mutation'] |
146 | | - const variables = 'bar234' |
147 | | - |
148 | | - const { mutate } = useMutation({ |
149 | | - mutationKey: mutationKey, |
150 | | - mutationFn: (params: string) => sleep(0).then(() => params), |
151 | | - }) |
152 | | - |
153 | | - mutate(variables) |
154 | | - |
155 | | - const mutationState = useMutationState() |
156 | | - |
157 | | - expect(mutationState.value[0]?.variables).toEqual(variables) |
158 | | - }) |
159 | | - |
160 | | - it('should work with options getter and be reactive', async () => { |
161 | | - const keyRef = ref('useMutationStateGetter2') |
162 | | - const variables = 'foo123' |
163 | | - |
164 | | - const { mutate } = useMutation({ |
165 | | - mutationKey: ['useMutationStateGetter'], |
166 | | - mutationFn: (params: string) => sleep(10).then(() => params), |
167 | | - }) |
168 | | - |
169 | | - mutate(variables) |
170 | | - |
171 | | - const mutationState = useMutationState(() => ({ |
172 | | - filters: { mutationKey: [keyRef.value], status: 'pending' }, |
173 | | - select: (mutation) => mutation.state.variables, |
174 | | - })) |
175 | | - |
176 | | - expect(mutationState.value).toEqual([]) |
177 | | - |
178 | | - keyRef.value = 'useMutationStateGetter' |
179 | | - |
180 | | - await vi.advanceTimersByTimeAsync(0) |
181 | | - |
182 | | - expect(mutationState.value).toEqual([variables]) |
183 | | - }) |
184 | | -}) |
0 commit comments