From 85f2c4844856b65bcf290237660f8c5571de7051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 2 Nov 2021 08:38:46 +0100 Subject: [PATCH] Toolkit: Don't to show console errors in tests (#41078) --- .../grafana-toolkit/src/config/jest.plugin.config.test.ts | 7 +++++++ .../grafana-toolkit/src/config/webpack/loaders.test.ts | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/grafana-toolkit/src/config/jest.plugin.config.test.ts b/packages/grafana-toolkit/src/config/jest.plugin.config.test.ts index 851d5ad8c88..021d5c37ca1 100644 --- a/packages/grafana-toolkit/src/config/jest.plugin.config.test.ts +++ b/packages/grafana-toolkit/src/config/jest.plugin.config.test.ts @@ -1,7 +1,14 @@ import { jestConfig, allowedJestConfigOverrides } from './jest.plugin.config'; describe('Jest config', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + it('should throw if not supported overrides provided', () => { + // Do not show console error,log when running test + jest.spyOn(console, 'error').mockImplementation(); + jest.spyOn(console, 'log').mockImplementation(); const getConfig = () => jestConfig(`${__dirname}/mocks/jestSetup/unsupportedOverrides`); expect(getConfig).toThrow('Provided Jest config is not supported'); diff --git a/packages/grafana-toolkit/src/config/webpack/loaders.test.ts b/packages/grafana-toolkit/src/config/webpack/loaders.test.ts index e06d631ae60..7f5b47e5755 100644 --- a/packages/grafana-toolkit/src/config/webpack/loaders.test.ts +++ b/packages/grafana-toolkit/src/config/webpack/loaders.test.ts @@ -2,11 +2,10 @@ import { getStylesheetEntries, hasThemeStylesheets } from './loaders'; describe('Loaders', () => { describe('stylesheet helpers', () => { - const logSpy = jest.spyOn(console, 'log').mockImplementation(); + jest.spyOn(console, 'log').mockImplementation(); afterAll(() => { - logSpy.mockRestore(); - logSpy.mockRestore(); + jest.restoreAllMocks(); }); describe('getStylesheetEntries', () => { @@ -24,10 +23,12 @@ describe('Loaders', () => { describe('hasThemeStylesheets', () => { it('throws when only one theme file is defined', () => { + jest.spyOn(console, 'error').mockImplementation(); const result = () => { hasThemeStylesheets(`${__dirname}/../mocks/stylesheetsSupport/missing-theme-file`); }; expect(result).toThrow(); + jest.restoreAllMocks(); }); it('returns false when no theme files present', () => {