Skip to content

Commit 04fa8d1

Browse files
committed
test(core): Restore spies between GlobalErrorBoundary tests
Individual tests created jest.spyOn() for lastEventId, captureReactException, and console.error but only some restored them, leaking mocks into subsequent tests. Centralize in before/afterEach: re-silence console.error per-test and call restoreAllMocks() after each so every inline spy is cleaned up, including those the file didn't explicitly track.
1 parent b619a09 commit 04fa8d1

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

packages/core/test/GlobalErrorBoundary.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ function Ok(): React.ReactElement {
2727
}
2828

2929
describe('GlobalErrorBoundary', () => {
30-
// react-test-renderer / React surfaces a console.error for uncaught exceptions
31-
// routed through componentDidCatch. Silence to keep test output clean.
32-
let errorSpy: jest.SpyInstance;
33-
beforeAll(() => {
34-
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
35-
});
36-
afterAll(() => {
37-
errorSpy.mockRestore();
38-
});
39-
4030
beforeEach(() => {
4131
_resetGlobalErrorBus();
32+
// react-test-renderer / React surfaces a console.error for uncaught
33+
// exceptions routed through componentDidCatch. Silence per-test so it
34+
// survives restoreAllMocks() in afterEach.
35+
jest.spyOn(console, 'error').mockImplementation(() => {});
36+
});
37+
38+
afterEach(() => {
39+
// Restore every jest.spyOn() created in beforeEach or inside individual
40+
// tests (lastEventId, captureReactException, …) so they don't leak into
41+
// subsequent tests.
42+
jest.restoreAllMocks();
4243
});
4344

4445
test('renders children when no error occurs', () => {
@@ -209,7 +210,6 @@ describe('GlobalErrorBoundary', () => {
209210

210211
expect(getByTestId('fallback').props.children.join('')).toBe('fallback:global-once');
211212
expect(captureReactExceptionSpy).not.toHaveBeenCalled();
212-
captureReactExceptionSpy.mockRestore();
213213
});
214214

215215
test('surfaces the published eventId to the fallback for global errors', () => {

0 commit comments

Comments
 (0)