Unverified Commit 964d0634 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Fix: createRouterAct "reject" config (#81720)

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.
parent 6f88000f
......@@ -72,6 +72,7 @@ export function createRouterAct(
}
let expectedResponses: Array<ExpectedResponseConfig> | null
let forbiddenResponses: Array<ExpectedResponseConfig> | null = null
let shouldBlockAll = false
if (config === undefined || config === null) {
// Default. Expect at least one request, but don't assert on the response.
......@@ -101,6 +102,7 @@ export function createRouterAct(
expectedResponses = [config]
} else {
expectedResponses = []
forbiddenResponses = [config]
}
} else {
expectedResponses = []
......@@ -113,6 +115,12 @@ export function createRouterAct(
}
if (item.block !== 'reject') {
expectedResponses.push(item)
} else {
if (forbiddenResponses === null) {
forbiddenResponses = [item]
} else {
forbiddenResponses.push(item)
}
}
}
}
......@@ -288,14 +296,11 @@ ${fulfilled.body}
`
throw error
}
if (expectedResponses !== null) {
let alreadyMatchedByThisResponse: string | null = null
for (const expectedResponse of expectedResponses) {
const includes = expectedResponse.includes
const block = expectedResponse.block
if (forbiddenResponses !== null) {
for (const forbiddenResponse of forbiddenResponses) {
const includes = forbiddenResponse.includes
if (fulfilled.body.includes(includes)) {
if (block === 'reject') {
error.message = `
error.message = `
Received a response containing an unexpected substring:
Rejected substring: ${includes}
......@@ -303,9 +308,16 @@ Rejected substring: ${includes}
Response:
${fulfilled.body}
`
throw error
}
throw error
}
}
}
if (expectedResponses !== null) {
let alreadyMatchedByThisResponse: string | null = null
for (const expectedResponse of expectedResponses) {
const includes = expectedResponse.includes
const block = expectedResponse.block
if (fulfilled.body.includes(includes)) {
// Match. Don't check yet whether the responses are received
// in the expected order. Instead collect all the matches and
// check at the end so we can include a diff in the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment