Skip to content

Commit 3599efb

Browse files
committed
Fix: createRouterAct "reject" config
Fixes a problem with the internal `createRouterAct` testing helper where the `block: "reject"` option would not error correctly, leading to potential false negatives. I think I accidentally broke this when I added the ability to provide an array of expected responses.
1 parent 9088ece commit 3599efb

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/e2e/app-dir/segment-cache/router-act.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function createRouterAct(
7272
}
7373

7474
let expectedResponses: Array<ExpectedResponseConfig> | null
75+
let forbiddenResponses: Array<ExpectedResponseConfig> | null = null
7576
let shouldBlockAll = false
7677
if (config === undefined || config === null) {
7778
// Default. Expect at least one request, but don't assert on the response.
@@ -101,6 +102,7 @@ export function createRouterAct(
101102
expectedResponses = [config]
102103
} else {
103104
expectedResponses = []
105+
forbiddenResponses = [config]
104106
}
105107
} else {
106108
expectedResponses = []
@@ -113,6 +115,8 @@ export function createRouterAct(
113115
}
114116
if (item.block !== 'reject') {
115117
expectedResponses.push(item)
118+
} else {
119+
forbiddenResponses = [item]
116120
}
117121
}
118122
}
@@ -288,24 +292,28 @@ ${fulfilled.body}
288292
`
289293
throw error
290294
}
291-
if (expectedResponses !== null) {
292-
let alreadyMatchedByThisResponse: string | null = null
293-
for (const expectedResponse of expectedResponses) {
294-
const includes = expectedResponse.includes
295-
const block = expectedResponse.block
295+
if (forbiddenResponses !== null) {
296+
for (const forbiddenResponse of forbiddenResponses) {
297+
const includes = forbiddenResponse.includes
296298
if (fulfilled.body.includes(includes)) {
297-
if (block === 'reject') {
298-
error.message = `
299+
error.message = `
299300
Received a response containing an unexpected substring:
300301
301302
Rejected substring: ${includes}
302303
303304
Response:
304305
${fulfilled.body}
305306
`
306-
throw error
307-
}
308-
307+
throw error
308+
}
309+
}
310+
}
311+
if (expectedResponses !== null) {
312+
let alreadyMatchedByThisResponse: string | null = null
313+
for (const expectedResponse of expectedResponses) {
314+
const includes = expectedResponse.includes
315+
const block = expectedResponse.block
316+
if (fulfilled.body.includes(includes)) {
309317
// Match. Don't check yet whether the responses are received
310318
// in the expected order. Instead collect all the matches and
311319
// check at the end so we can include a diff in the

0 commit comments

Comments
 (0)