From 2bf7c02f0ecddff385f8acb9c797e65884f1a3b3 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 14 Mar 2022 14:17:37 +0100 Subject: [PATCH] Don't hide console error|warn in inspectedElement-test (#24086) --- .../src/__tests__/inspectedElement-test.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js index 3060d2c325fc0..e6f8c3277d3a2 100644 --- a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js +++ b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js @@ -459,7 +459,7 @@ describe('InspectedElement', () => { const prevInspectedElement = inspectedElement; // This test causes an intermediate error to be logged but we can ignore it. - console.error = () => {}; + jest.spyOn(console, 'error').mockImplementation(() => {}); // Wait for our check-for-updates poll to get the new data. jest.runOnlyPendingTimers(); @@ -2804,16 +2804,18 @@ describe('InspectedElement', () => { ); // Suppress expected error and warning. - const originalError = console.error; - const originalWarn = console.warn; - console.error = () => {}; - console.warn = () => {}; + const consoleErrorMock = jest + .spyOn(console, 'error') + .mockImplementation(() => {}); + const consoleWarnMock = jest + .spyOn(console, 'warn') + .mockImplementation(() => {}); // now force error state on await toggleError(true); - console.error = originalError; - console.warn = originalWarn; + consoleErrorMock.mockRestore(); + consoleWarnMock.mockRestore(); // we are in error state now, won't show up withErrorsOrWarningsIgnored(['Invalid index'], () => {