Skip to content

Commit

Permalink
test: reduce noise from test warnings (#8251)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Sep 25, 2024
1 parent cdb1297 commit e680921
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import 'whatwg-fetch';
import 'regenerator-runtime';
import { beforeAll, vi } from 'vitest';

class ResizeObserver {
observe() {}
Expand All @@ -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);
}
});
});
8 changes: 7 additions & 1 deletion frontend/src/utils/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit e680921

Please sign in to comment.