From 1965b9d88da866e5709c69869e0863eff38da76c Mon Sep 17 00:00:00 2001 From: kwasniew Date: Wed, 25 Sep 2024 12:45:31 +0200 Subject: [PATCH] test: reduce noise from test warnings --- frontend/src/setupTests.ts | 18 ++++++++++++++++++ frontend/src/utils/testServer.ts | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/setupTests.ts b/frontend/src/setupTests.ts index 25e7a167846f..0018fca294f3 100644 --- a/frontend/src/setupTests.ts +++ b/frontend/src/setupTests.ts @@ -1,6 +1,7 @@ import '@testing-library/jest-dom'; import 'whatwg-fetch'; import 'regenerator-runtime'; +import { beforeAll, vi } from 'vitest'; class ResizeObserver { observe() {} @@ -13,3 +14,20 @@ if (!window.ResizeObserver) { } process.env.TZ = 'UTC'; + +// ignore known React warnings +const consoleError = console.error; +beforeAll(() => { + vi.spyOn(console, 'error').mockImplementation((...args) => { + if ( + !( + typeof args[0] === 'string' && + args[0].includes( + 'Warning: An update to %s inside a test was not wrapped in act', + ) + ) + ) { + consoleError(...args); + } + }); +}); diff --git a/frontend/src/utils/testServer.ts b/frontend/src/utils/testServer.ts index 4d1351006b07..c3ec37d2005a 100644 --- a/frontend/src/utils/testServer.ts +++ b/frontend/src/utils/testServer.ts @@ -4,7 +4,13 @@ import { http, HttpResponse } from 'msw'; export const testServerSetup = (): SetupServer => { const server = setupServer(); - beforeAll(() => server.listen()); + beforeAll(() => + server.listen({ + onUnhandledRequest() { + return HttpResponse.error(); + }, + }), + ); afterAll(() => server.close()); afterEach(() => server.resetHandlers());