@samitouri / QOS-React-2 / commits / 657698e48d

[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.

Josh Story committed Apr 7, 2023 at 14:14 UTC 657698e48d5b093b4ea5a7684e26d3fdd16695f2
1 file changed +11 -3
packages/internal-test-utils/ReactInternalTestUtils.js
+11 -3
@@ -141,10 +141,18 @@ export async function waitForThrow(expectedError: mixed): mixed {
141 typeof expectedError === 'string' &&
142 typeof x === 'object' &&
143 x !== null &&
144 - typeof x.message === 'string' &&
145 - x.message.includes(expectedError)
144 + typeof x.message === 'string'
145 ) {
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 + }
156 }
157 error.message = `
158 Expected error was not thrown.