Skip to content

Commit 2751bec

Browse files
authored
Merge pull request #4877 from aryaemami59/chore/fix-env-handling
chore: improve handling of environment variables in tests
2 parents 66ff32a + be33129 commit 2751bec

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

packages/toolkit/src/query/tests/createApi.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ describe('wrong tagTypes log errors', () => {
159159
['invalidateWrongTypeWithId', true],
160160
['invalidateWrongTypeWithIdAndCallback', true],
161161
])(`endpoint %s should log an error? %s`, async (endpoint, shouldError) => {
162+
vi.stubEnv('NODE_ENV', 'development')
163+
162164
// @ts-ignore
163165
store.dispatch(api.endpoints[endpoint].initiate())
164166
let result: { status: string }
@@ -402,6 +404,8 @@ describe('endpoint definition typings', () => {
402404
})
403405

404406
test('warn on wrong tagType', async () => {
407+
vi.stubEnv('NODE_ENV', 'development')
408+
405409
const storeRef = setupApiStore(api, undefined, {
406410
withoutTestLifecycles: true,
407411
})

packages/toolkit/src/query/tests/infiniteQueries.test.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
1-
import { configureStore, isAllOf } from '@reduxjs/toolkit'
2-
import {
3-
act,
4-
fireEvent,
5-
render,
6-
renderHook,
7-
screen,
8-
waitFor,
9-
} from '@testing-library/react'
10-
import userEvent from '@testing-library/user-event'
11-
import { HttpResponse, delay, http } from 'msw'
12-
import util from 'util'
13-
import type {
14-
InfiniteQueryActionCreatorResult,
15-
QueryCacheKey,
16-
} from '@reduxjs/toolkit/query/react'
1+
import { server } from '@internal/query/tests/mocks/server'
2+
import type { InfiniteQueryActionCreatorResult } from '@reduxjs/toolkit/query/react'
173
import {
184
QueryStatus,
195
createApi,
20-
fetchBaseQuery,
216
fakeBaseQuery,
22-
skipToken,
7+
fetchBaseQuery,
238
} from '@reduxjs/toolkit/query/react'
24-
import {
25-
actionsReducer,
26-
setupApiStore,
27-
withProvider,
28-
} from '../../tests/utils/helpers'
29-
import type { BaseQueryApi } from '../baseQueryTypes'
30-
import { server } from '@internal/query/tests/mocks/server'
9+
import { HttpResponse, delay, http } from 'msw'
10+
import { actionsReducer, setupApiStore } from '../../tests/utils/helpers'
3111
import type { InfiniteQueryResultFlags } from '../core/buildSelectors'
3212

3313
describe('Infinite queries', () => {
@@ -171,12 +151,6 @@ describe('Infinite queries', () => {
171151

172152
hitCounter = 0
173153
queryCounter = 0
174-
175-
process.env.NODE_ENV = 'development'
176-
})
177-
178-
afterEach(() => {
179-
process.env.NODE_ENV = 'test'
180154
})
181155

182156
type InfiniteQueryResult = Awaited<InfiniteQueryActionCreatorResult<any>>
@@ -387,6 +361,8 @@ describe('Infinite queries', () => {
387361
})
388362

389363
test('validates maxPages during createApi call', async () => {
364+
vi.stubEnv('NODE_ENV', 'development')
365+
390366
const createApiWithMaxPages = (
391367
maxPages: number,
392368
getPreviousPageParam: (() => number) | undefined,

packages/toolkit/vitest.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export default defineConfig({
2323
setupFiles: ['./vitest.setup.ts'],
2424
include: ['./src/**/*.(spec|test).[jt]s?(x)'],
2525
server: { deps: { inline: ['redux', '@reduxjs/toolkit'] } },
26+
unstubEnvs: true,
2627
},
2728
})

0 commit comments

Comments
 (0)