From 6a01abd9ea6daddf6589e4217d494928e7930649 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Tue, 21 May 2024 17:16:45 +0200 Subject: [PATCH] Fix assertConsoleErrorDev on message mismatch with withoutStack: true --- .../__tests__/ReactInternalTestUtils-test.js | 12 +++++++++++- packages/internal-test-utils/consoleMock.js | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js b/packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js index fedcbc9770436..1ee1bcf2b5662 100644 --- a/packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js +++ b/packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js @@ -2427,7 +2427,17 @@ describe('ReactInternalTestUtils console assertions', () => { ], ]); }); - expect(message).toMatchInlineSnapshot(`"message.replace is not a function"`); + expect(message).toMatchInlineSnapshot(` + "assertConsoleErrorDev(expected) + + Unexpected error(s) recorded. + + - Expected errors + + Received errors + + - Hello + + Bye " + `); }); }); diff --git a/packages/internal-test-utils/consoleMock.js b/packages/internal-test-utils/consoleMock.js index 3b9ef2f8c0e53..45a59d2b4cb29 100644 --- a/packages/internal-test-utils/consoleMock.js +++ b/packages/internal-test-utils/consoleMock.js @@ -464,7 +464,12 @@ export function createLogAssertion( function printDiff() { return `${diff( expectedMessages - .map(message => message.replace('\n', ' ')) + .map(messageOrTuple => { + const message = Array.isArray(messageOrTuple) + ? messageOrTuple[0] + : messageOrTuple; + return message.replace('\n', ' '); + }) .join('\n'), receivedLogs.map(message => message.replace('\n', ' ')).join('\n'), {