[Tests] waitForThrow should diff strings (#26568)

Currently, `waitForThrow` tries to diff the expected value against the
thrown value if it doesn't match. However if the expectation is a
string, we are not diffing against the thrown message. This commit makes
it so if we are matching against message we also diff against message.
This commit is contained in:
Josh Story
2023-04-07 14:14:08 -07:00
committed by GitHub
parent dd5365878d
commit 657698e48d

View File

@@ -141,10 +141,18 @@ export async function waitForThrow(expectedError: mixed): mixed {
typeof expectedError === 'string' &&
typeof x === 'object' &&
x !== null &&
typeof x.message === 'string' &&
x.message.includes(expectedError)
typeof x.message === 'string'
) {
return x;
if (x.message.includes(expectedError)) {
return x;
} else {
error.message = `
Expected error was not thrown.
${diff(expectedError, x.message)}
`;
throw error;
}
}
error.message = `
Expected error was not thrown.