From 6dfbd27e847cfc7a48fa46e905bc084bc70589b9 Mon Sep 17 00:00:00 2001 From: Josh Story Date: Wed, 5 Apr 2023 10:17:58 -0700 Subject: [PATCH] `waitForThrow` should diff strings 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. --- .../internal-test-utils/ReactInternalTestUtils.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/internal-test-utils/ReactInternalTestUtils.js b/packages/internal-test-utils/ReactInternalTestUtils.js index 29744830abea6..8e68e83344241 100644 --- a/packages/internal-test-utils/ReactInternalTestUtils.js +++ b/packages/internal-test-utils/ReactInternalTestUtils.js @@ -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.