Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/react-query/src/__tests__/useMutationState.test-d.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expectTypeOf, it } from 'vitest'
import { useMutationState } from '../useMutationState'
import type { MutationState, MutationStatus } from '@tanstack/query-core'

describe('useMutationState', () => {
it('should default to QueryState', () => {
const result = useMutationState({
filters: { status: 'pending' },
})

expectTypeOf(result).toEqualTypeOf<
Array<MutationState<unknown, Error, unknown, unknown>>
>()
})
it('should infer with select', () => {
const result = useMutationState({
filters: { status: 'pending' },
select: (mutation) => mutation.state.status,
})

expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
})
})
39 changes: 2 additions & 37 deletions packages/react-query/src/__tests__/useMutationState.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import {
afterEach,
beforeEach,
describe,
expect,
expectTypeOf,
it,
vi,
} from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { fireEvent, render } from '@testing-library/react'
import * as React from 'react'
import { useIsMutating, useMutationState } from '../useMutationState'
import { useMutation } from '../useMutation'
import {
createQueryClient,
doNotExecute,
renderWithClient,
sleep,
} from './utils'
import type { MutationState, MutationStatus } from '@tanstack/query-core'
import { createQueryClient, renderWithClient, sleep } from './utils'

describe('useIsMutating', () => {
beforeEach(() => {
Expand Down Expand Up @@ -182,27 +168,6 @@ describe('useIsMutating', () => {
})

describe('useMutationState', () => {
describe('types', () => {
it('should default to QueryState', () => {
doNotExecute(() => {
const result = useMutationState({
filters: { status: 'pending' },
})

expectTypeOf(result).toEqualTypeOf<Array<MutationState>>()
})
})
it('should infer with select', () => {
doNotExecute(() => {
const result = useMutationState({
filters: { status: 'pending' },
select: (mutation) => mutation.state.status,
})

expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
})
})
})
it('should return variables after calling mutate', async () => {
const queryClient = createQueryClient()
const variables: Array<Array<unknown>> = []
Expand Down
2 changes: 0 additions & 2 deletions packages/react-query/src/__tests__/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,3 @@ export function setIsServer(isServer: boolean) {
})
}
}

export const doNotExecute = (_func: () => void) => true
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this

Loading