Skip to content

Commit b3a2d59

Browse files
committed
Fix timeout tests
1 parent 9576c3d commit b3a2d59

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ describe('additional transformResponse behaviors', () => {
681681

682682
test('transformResponse handles an async transformation and returns the merged data (query)', async () => {
683683
const result = await storeRef.store.dispatch(api.endpoints.query.initiate())
684-
console.log(result)
685684

686685
expect(result.data).toEqual({ value: 'success', banana: 'bread' })
687686
})
@@ -718,7 +717,6 @@ describe('additional transformResponse behaviors', () => {
718717
response: {
719718
headers: {
720719
'content-type': 'application/json',
721-
// 'x-powered-by': 'msw',
722720
},
723721
},
724722
},
@@ -739,7 +737,6 @@ describe('additional transformResponse behaviors', () => {
739737
response: {
740738
headers: {
741739
'content-type': 'application/json',
742-
// 'x-powered-by': 'msw',
743740
},
744741
},
745742
},

packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -970,23 +970,25 @@ describe('fetchBaseQuery', () => {
970970
})
971971

972972
test('Global timeout', async () => {
973-
let reject: () => void
974-
const donePromise = new Promise((resolve, _reject) => {
975-
reject = _reject
976-
})
977973
server.use(
978974
http.get(
979975
'https://example.com/empty1',
980-
async ({ request, params, cookies, requestId }) => {
981-
await Promise.race([waitMs(2000), donePromise])
976+
async ({ request, cookies, params, requestId }) => {
977+
await delay(300)
978+
982979
return HttpResponse.json({
983980
...request,
981+
cookies,
982+
params,
983+
requestId,
984+
url: new URL(request.url),
984985
headers: headersToObject(request.headers),
985986
})
986987
},
987988
{ once: true }
988989
)
989990
)
991+
990992
const globalizedBaseQuery = fetchBaseQuery({
991993
baseUrl,
992994
fetchFn: fetchFn as any,
@@ -1003,7 +1005,6 @@ describe('fetchBaseQuery', () => {
10031005
status: 'TIMEOUT_ERROR',
10041006
error: 'AbortError: The operation was aborted.',
10051007
})
1006-
reject!()
10071008
})
10081009
})
10091010
})
@@ -1089,33 +1090,34 @@ describe('still throws on completely unexpected errors', () => {
10891090

10901091
describe('timeout', () => {
10911092
test('throws a timeout error when a request takes longer than specified timeout duration', async () => {
1092-
let reject: () => void
1093-
const donePromise = new Promise((resolve, _reject) => {
1094-
reject = _reject
1095-
})
1096-
10971093
server.use(
10981094
http.get(
10991095
'https://example.com/empty2',
1100-
async ({ request }) => {
1101-
await Promise.race([waitMs(3000), donePromise])
1096+
async ({ request, cookies, params, requestId }) => {
1097+
await delay(300)
1098+
11021099
return HttpResponse.json({
11031100
...request,
1101+
url: new URL(request.url),
1102+
cookies,
1103+
params,
1104+
requestId,
11041105
headers: headersToObject(request.headers),
11051106
})
11061107
},
11071108
{ once: true }
11081109
)
11091110
)
1111+
11101112
const result = await baseQuery(
11111113
{ url: '/empty2', timeout: 200 },
11121114
commonBaseQueryApi,
11131115
{}
11141116
)
1117+
11151118
expect(result?.error).toEqual({
11161119
status: 'TIMEOUT_ERROR',
11171120
error: 'AbortError: The operation was aborted.',
11181121
})
1119-
reject!()
11201122
})
11211123
})

packages/toolkit/vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export default defineConfig({
2525
//'^@reduxjs/toolkit/dist/(.*)$': '<rootDir>/src/*',
2626
'@internal': path.join(__dirname, './src'),
2727
},
28-
server: { deps: { inline: ['redux', '@reduxjs/toolkit'], } },
28+
server: { deps: { inline: ['redux', '@reduxjs/toolkit'] } },
2929
},
3030
})

0 commit comments

Comments
 (0)