Don't hide console error|warn in inspectedElement-test (#24086)
Sebastian Silbermann committed
Mar 14, 2022 at 14:17 UTC
2bf7c02f0ecddff385f8acb9c797e65884f1a3b3
1 file changed
+9
-7
packages/react-devtools-shared/src/__tests__/inspectedElement-test.js
+9
-7
@@ -459,7 +459,7 @@ describe('InspectedElement', () => {
459
const prevInspectedElement = inspectedElement;
460
461
// This test causes an intermediate error to be logged but we can ignore it.
462
- console.error = () => {};
462
+ jest.spyOn(console, 'error').mockImplementation(() => {});
463
464
// Wait for our check-for-updates poll to get the new data.
465
jest.runOnlyPendingTimers();
@@ -2804,16 +2804,18 @@ describe('InspectedElement', () => {
2804
);
2805
2806
// 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(() => {});
2813
2814
// now force error state on <Example />
2815
await toggleError(true);
2816
2815
- console.error = originalError;
2816
- console.warn = originalWarn;
2817
+ consoleErrorMock.mockRestore();
2818
+ consoleWarnMock.mockRestore();
2819
2820
// we are in error state now, <Example /> won't show up
2821
withErrorsOrWarningsIgnored(['Invalid index'], () => {