Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenz Weber committed Apr 7, 2022
1 parent 169d359 commit 776e24f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('hooks tests', () => {
expect(screen.getByTestId('isLoading').textContent).toBe('false')
)
// We call a refetch, should still be `false`
act(() => refetch())
act(() => void refetch())
await waitFor(() =>
expect(screen.getByTestId('isFetching').textContent).toBe('true')
)
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('hooks tests', () => {
expect(getRenderCount()).toBe(5)

// We call a refetch, should set `isFetching` to true, then false when complete/errored
act(() => refetchMe())
act(() => void refetchMe())
await waitFor(() => {
expect(screen.getByTestId('isLoading').textContent).toBe('false')
expect(screen.getByTestId('isFetching').textContent).toBe('true')
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/tests/errorHandling.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('query error handling', () => {
)
)

act(result.current.refetch)
act(() => void result.current.refetch())

await hookWaitFor(() => expect(result.current.isFetching).toBeFalsy())
expect(result.current).toEqual(
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('query error handling', () => {
})
)

act(result.current.refetch)
act(() => void result.current.refetch())

await hookWaitFor(() => expect(result.current.isFetching).toBeFalsy())
expect(result.current).toEqual(
Expand Down
16 changes: 11 additions & 5 deletions packages/toolkit/src/query/tests/unionTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe.skip('TS only tests', () => {
})
// pre41-remove-end

test('queryHookResult (without selector) union', () => {
test('queryHookResult (without selector) union', async () => {
const useQueryStateResult = api.endpoints.test.useQueryState()
const useQueryResult = api.endpoints.test.useQuery()
const useQueryStateWithSelectFromResult = api.endpoints.test.useQueryState(
Expand All @@ -353,12 +353,15 @@ describe.skip('TS only tests', () => {
}
)

const { refetch: _omit, ...useQueryResultWithoutMethods } = useQueryResult
const { refetch, ...useQueryResultWithoutMethods } = useQueryResult
expectExactType(useQueryStateResult)(useQueryResultWithoutMethods)
expectExactType(useQueryStateWithSelectFromResult)(
// @ts-expect-error
useQueryResultWithoutMethods
)
expectType<ReturnType<ReturnType<typeof api.endpoints.test.select>>>(
await refetch()
)
})

test('useQueryState (with selectFromResult)', () => {
Expand Down Expand Up @@ -391,8 +394,8 @@ describe.skip('TS only tests', () => {
})(result)
})

test('useQuery (with selectFromResult)', () => {
const result = api.endpoints.test.useQuery(undefined, {
test('useQuery (with selectFromResult)', async () => {
const { refetch, ...result } = api.endpoints.test.useQuery(undefined, {
selectFromResult({
data,
isLoading,
Expand All @@ -418,8 +421,11 @@ describe.skip('TS only tests', () => {
isFetching: true,
isSuccess: false,
isError: false,
refetch: () => {},
})(result)

expectType<ReturnType<ReturnType<typeof api.endpoints.test.select>>>(
await refetch()
)
})

test('useMutation union', () => {
Expand Down

0 comments on commit 776e24f

Please sign in to comment.