From 0282d5f9c3a055d449a555bc30f4c8a9822aef44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Wed, 9 Feb 2022 13:45:36 +0100 Subject: [PATCH] Chore: Remove console output in ErrorBoundary.test.tsx (#45138) --- .../components/ErrorBoundary/ErrorBoundary.test.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/grafana-ui/src/components/ErrorBoundary/ErrorBoundary.test.tsx b/packages/grafana-ui/src/components/ErrorBoundary/ErrorBoundary.test.tsx index ea648f1a84f..925210cfcd7 100644 --- a/packages/grafana-ui/src/components/ErrorBoundary/ErrorBoundary.test.tsx +++ b/packages/grafana-ui/src/components/ErrorBoundary/ErrorBoundary.test.tsx @@ -9,7 +9,18 @@ const ErrorThrower: FC<{ error: Error }> = ({ error }) => { throw error; }; +// According to this issue https://github.com/facebook/react/issues/15069 componentDidCatch logs errors to console.error unconditionally. +// Let's make sure we don't output that to console.error in the tests. +let consoleSpy: jest.SpyInstance; describe('ErrorBoundary', () => { + beforeEach(() => { + consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + }); + + afterEach(() => { + consoleSpy.mockRestore(); + }); + it('should catch error and report it to sentry, including react component stack in context', async () => { const problem = new Error('things went terribly wrong'); render(