Skip to content

Commit

Permalink
[Tests] waitForThrow should diff strings (#26568)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnoff committed Apr 7, 2023
1 parent dd53658 commit 657698e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/internal-test-utils/ReactInternalTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 657698e

Please sign in to comment.