Skip to content

Commit

Permalink
Replace dist imports with @internal imports
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Jan 29, 2024
1 parent 3418c5a commit 77511c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 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
@@ -1,4 +1,6 @@
import type { SubscriptionOptions } from '@internal/query/core/apiState'
import type { SubscriptionSelectors } from '@internal/query/core/buildMiddleware/types'
import { server } from '@internal/query/tests/mocks/server'
import { countObjectKeys } from '@internal/query/utils/countObjectKeys'
import {
actionsReducer,
Expand All @@ -13,7 +15,6 @@ import {
createListenerMiddleware,
createSlice,
} from '@reduxjs/toolkit'
import type { SubscriptionOptions } from '@reduxjs/toolkit/dist/query/core/apiState'
import {
QueryStatus,
createApi,
Expand All @@ -32,7 +33,6 @@ import userEvent from '@testing-library/user-event'
import { HttpResponse, http } from 'msw'
import { useEffect, useState } from 'react'
import type { MockInstance } from 'vitest'
import { server } from './mocks/server'

// Just setup a temporary in-memory counter for tests that `getIncrementedAmount`.
// This can be used to test how many renders happen due to data changes or
Expand Down
42 changes: 21 additions & 21 deletions packages/toolkit/src/query/tests/queryFn.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { QuerySubState } from '@internal/query/core/apiState'
import type { Post } from '@internal/query/tests/mocks/handlers'
import { posts } from '@internal/query/tests/mocks/handlers'
import { actionsReducer, setupApiStore } from '@internal/tests/utils/helpers'
import type { SerializedError } from '@reduxjs/toolkit'
import { configureStore } from '@reduxjs/toolkit'
import type { BaseQueryFn, FetchBaseQueryError } from '@reduxjs/toolkit/query'
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
import type { Post } from './mocks/handlers'
import { posts } from './mocks/handlers'
import { actionsReducer, setupApiStore } from '../../tests/utils/helpers'
import type { QuerySubState } from '@reduxjs/toolkit/dist/query/core/apiState'

describe('queryFn base implementation tests', () => {
const baseQuery: BaseQueryFn<string, { wrappedByBaseQuery: string }, string> =
vi.fn((arg: string) =>
arg.includes('withErrorQuery')
? { error: `cut${arg}` }
: { data: { wrappedByBaseQuery: arg } }
: { data: { wrappedByBaseQuery: arg } },
)

const api = createApi({
Expand Down Expand Up @@ -193,27 +193,27 @@ describe('queryFn base implementation tests', () => {
endpointName.includes('Throw')
? `An unhandled error occurred processing a request for the endpoint "${endpointName}".
In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: resultFrom(${endpointName})]`
: ''
: '',
)
if (expectedResult === 'data') {
expect(result).toEqual(
expect.objectContaining({
data: `resultFrom(${endpointName})`,
})
}),
)
} else if (expectedResult === 'error') {
expect(result).toEqual(
expect.objectContaining({
error: `resultFrom(${endpointName})`,
})
}),
)
} else {
expect(result).toEqual(
expect.objectContaining({
error: expect.objectContaining({
message: `resultFrom(${endpointName})`,
}),
})
}),
)
}
})
Expand Down Expand Up @@ -241,28 +241,28 @@ describe('queryFn base implementation tests', () => {
endpointName.includes('Throw')
? `An unhandled error occurred processing a request for the endpoint "${endpointName}".
In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: resultFrom(${endpointName})]`
: ''
: '',
)

if (expectedResult === 'data') {
expect(result).toEqual(
expect.objectContaining({
data: `resultFrom(${endpointName})`,
})
}),
)
} else if (expectedResult === 'error') {
expect(result).toEqual(
expect.objectContaining({
error: `resultFrom(${endpointName})`,
})
}),
)
} else {
expect(result).toEqual(
expect.objectContaining({
error: expect.objectContaining({
message: `resultFrom(${endpointName})`,
}),
})
}),
)
}
})
Expand All @@ -275,12 +275,12 @@ describe('queryFn base implementation tests', () => {
result = await store.dispatch(thunk)
}).toHaveConsoleOutput(
`An unhandled error occurred processing a request for the endpoint "withNeither".
In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`
In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`,
)
expect(result!.error).toEqual(
expect.objectContaining({
message: 'endpointDefinition.queryFn is not a function',
})
}),
)
}
{
Expand All @@ -293,12 +293,12 @@ describe('queryFn base implementation tests', () => {
result = await store.dispatch(thunk)
}).toHaveConsoleOutput(
`An unhandled error occurred processing a request for the endpoint "mutationWithNeither".
In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`
In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: endpointDefinition.queryFn is not a function]`,
)
expect((result as any).error).toEqual(
expect.objectContaining({
message: 'endpointDefinition.queryFn is not a function',
})
}),
)
}
})
Expand Down Expand Up @@ -372,14 +372,14 @@ describe('usage scenario tests', () => {

it('can chain multiple queries together', async () => {
const result = await storeRef.store.dispatch(
api.endpoints.getRandomUser.initiate()
api.endpoints.getRandomUser.initiate(),
)
expect(result.data).toEqual(posts[1])
})

it('can wrap a service like Firebase', async () => {
const result = await storeRef.store.dispatch(
api.endpoints.getFirebaseUser.initiate(1)
api.endpoints.getFirebaseUser.initiate(1),
)
expect(result.data).toEqual(mockData)
})
Expand All @@ -388,7 +388,7 @@ describe('usage scenario tests', () => {
let result: QuerySubState<any>
await expect(async () => {
result = await storeRef.store.dispatch(
api.endpoints.getMissingFirebaseUser.initiate(1)
api.endpoints.getMissingFirebaseUser.initiate(1),
)
})
.toHaveConsoleOutput(`An unhandled error occurred processing a request for the endpoint "getMissingFirebaseUser".
Expand All @@ -399,7 +399,7 @@ describe('usage scenario tests', () => {
expect.objectContaining({
message: 'Missing user',
name: 'Error',
})
}),
)
})
})

0 comments on commit 77511c3

Please sign in to comment.