Skip to content

Commit 657698e

Browse files
authored
[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.
1 parent dd53658 commit 657698e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/internal-test-utils/ReactInternalTestUtils.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,18 @@ export async function waitForThrow(expectedError: mixed): mixed {
141141
typeof expectedError === 'string' &&
142142
typeof x === 'object' &&
143143
x !== null &&
144-
typeof x.message === 'string' &&
145-
x.message.includes(expectedError)
144+
typeof x.message === 'string'
146145
) {
147-
return x;
146+
if (x.message.includes(expectedError)) {
147+
return x;
148+
} else {
149+
error.message = `
150+
Expected error was not thrown.
151+
152+
${diff(expectedError, x.message)}
153+
`;
154+
throw error;
155+
}
148156
}
149157
error.message = `
150158
Expected error was not thrown.

0 commit comments

Comments
 (0)