Skip to content

Commit

Permalink
[Tests] waitForThrow should diff strings (facebook#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 authored and AndyPengc12 committed Apr 15, 2024
1 parent 251ddb4 commit 42f0be7
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 42f0be7

Please sign in to comment.