Chore: Enable jest-fail-on-console to prevent console errors in unit tests (#46835)

* Add jest-fail-on-console

* Fix last 2 console warnings

* Update package syntax
This commit is contained in:
Ashley Harrison 2022-03-22 17:03:07 +00:00 committed by GitHub
parent ba62f5ad5d
commit 04bbafb4a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 0 deletions

View File

@ -195,6 +195,7 @@
"jest": "27.5.0",
"jest-canvas-mock": "2.3.1",
"jest-date-mock": "1.0.8",
"jest-fail-on-console": "2.3.0",
"jest-junit": "13.0.0",
"jest-matcher-utils": "27.5.0",
"jest-mock-console": "1.2.3",

View File

@ -506,8 +506,10 @@ describe('DashboardModel', () => {
describe('Given model with time', () => {
let model: DashboardModel;
let consoleWarnSpy: jest.SpyInstance;
beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
model = new DashboardModel({
time: {
from: 'now-6h',
@ -521,6 +523,10 @@ describe('DashboardModel', () => {
};
});
afterEach(() => {
consoleWarnSpy.mockRestore();
});
it('hasTimeChanged should be true', () => {
expect(model.hasTimeChanged()).toBeTruthy();
});

View File

@ -37,6 +37,11 @@ jest.mock('../hooks/usePluginConfig.tsx', () => ({
})),
}));
jest.mock('../helpers.ts', () => ({
...jest.requireActual('../helpers.ts'),
updatePanels: jest.fn(),
}));
const renderPluginDetails = (
pluginOverride: Partial<CatalogPlugin>,
{

View File

@ -1,4 +1,8 @@
import '@testing-library/jest-dom';
import failOnConsole from 'jest-fail-on-console';
import { matchers } from './matchers';
failOnConsole({
shouldFailOnLog: true,
});
expect.extend(matchers);

View File

@ -20933,6 +20933,7 @@ __metadata:
jest: 27.5.0
jest-canvas-mock: 2.3.1
jest-date-mock: 1.0.8
jest-fail-on-console: 2.3.0
jest-junit: 13.0.0
jest-matcher-utils: 27.5.0
jest-mock-console: 1.2.3
@ -23609,6 +23610,15 @@ __metadata:
languageName: node
linkType: hard
"jest-fail-on-console@npm:2.3.0":
version: 2.3.0
resolution: "jest-fail-on-console@npm:2.3.0"
dependencies:
chalk: ^4.1.0
checksum: b0ce97a5f6bc11226a1eecb9406c98e42ce5e7197310019f3cb27495b43cc1d01aaee36b094ea46a23deffcb62b246ddccd5dfdefe525b72d8dad2c9f1f634ee
languageName: node
linkType: hard
"jest-get-type@npm:^26.3.0":
version: 26.3.0
resolution: "jest-get-type@npm:26.3.0"