Skip to content

Commit 2bf7c02

Browse files
authored
Don't hide console error|warn in inspectedElement-test (#24086)
1 parent 061ac27 commit 2bf7c02

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ describe('InspectedElement', () => {
459459
const prevInspectedElement = inspectedElement;
460460

461461
// This test causes an intermediate error to be logged but we can ignore it.
462-
console.error = () => {};
462+
jest.spyOn(console, 'error').mockImplementation(() => {});
463463

464464
// Wait for our check-for-updates poll to get the new data.
465465
jest.runOnlyPendingTimers();
@@ -2804,16 +2804,18 @@ describe('InspectedElement', () => {
28042804
);
28052805

28062806
// Suppress expected error and warning.
2807-
const originalError = console.error;
2808-
const originalWarn = console.warn;
2809-
console.error = () => {};
2810-
console.warn = () => {};
2807+
const consoleErrorMock = jest
2808+
.spyOn(console, 'error')
2809+
.mockImplementation(() => {});
2810+
const consoleWarnMock = jest
2811+
.spyOn(console, 'warn')
2812+
.mockImplementation(() => {});
28112813

28122814
// now force error state on <Example />
28132815
await toggleError(true);
28142816

2815-
console.error = originalError;
2816-
console.warn = originalWarn;
2817+
consoleErrorMock.mockRestore();
2818+
consoleWarnMock.mockRestore();
28172819

28182820
// we are in error state now, <Example /> won't show up
28192821
withErrorsOrWarningsIgnored(['Invalid index'], () => {

0 commit comments

Comments
 (0)