Skip to content

Commit b397fba

Browse files
authored
test(react-query): use test-d file for useMutationState (#9075)
1 parent fcb3d4a commit b397fba

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expectTypeOf, it } from 'vitest'
2+
import { useMutationState } from '../useMutationState'
3+
import type { MutationState, MutationStatus } from '@tanstack/query-core'
4+
5+
describe('useMutationState', () => {
6+
it('should default to QueryState', () => {
7+
const result = useMutationState({
8+
filters: { status: 'pending' },
9+
})
10+
11+
expectTypeOf(result).toEqualTypeOf<
12+
Array<MutationState<unknown, Error, unknown, unknown>>
13+
>()
14+
})
15+
it('should infer with select', () => {
16+
const result = useMutationState({
17+
filters: { status: 'pending' },
18+
select: (mutation) => mutation.state.status,
19+
})
20+
21+
expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
22+
})
23+
})

packages/react-query/src/__tests__/useMutationState.test.tsx

+2-37
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
import {
2-
afterEach,
3-
beforeEach,
4-
describe,
5-
expect,
6-
expectTypeOf,
7-
it,
8-
vi,
9-
} from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
102
import { fireEvent, render } from '@testing-library/react'
113
import * as React from 'react'
124
import { useIsMutating, useMutationState } from '../useMutationState'
135
import { useMutation } from '../useMutation'
14-
import {
15-
createQueryClient,
16-
doNotExecute,
17-
renderWithClient,
18-
sleep,
19-
} from './utils'
20-
import type { MutationState, MutationStatus } from '@tanstack/query-core'
6+
import { createQueryClient, renderWithClient, sleep } from './utils'
217

228
describe('useIsMutating', () => {
239
beforeEach(() => {
@@ -182,27 +168,6 @@ describe('useIsMutating', () => {
182168
})
183169

184170
describe('useMutationState', () => {
185-
describe('types', () => {
186-
it('should default to QueryState', () => {
187-
doNotExecute(() => {
188-
const result = useMutationState({
189-
filters: { status: 'pending' },
190-
})
191-
192-
expectTypeOf(result).toEqualTypeOf<Array<MutationState>>()
193-
})
194-
})
195-
it('should infer with select', () => {
196-
doNotExecute(() => {
197-
const result = useMutationState({
198-
filters: { status: 'pending' },
199-
select: (mutation) => mutation.state.status,
200-
})
201-
202-
expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
203-
})
204-
})
205-
})
206171
it('should return variables after calling mutate', async () => {
207172
const queryClient = createQueryClient()
208173
const variables: Array<Array<unknown>> = []

packages/react-query/src/__tests__/utils.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,3 @@ export function setIsServer(isServer: boolean) {
9292
})
9393
}
9494
}
95-
96-
export const doNotExecute = (_func: () => void) => true

0 commit comments

Comments
 (0)