1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

test: reduce noise from test warnings (#8251)

This commit is contained in:
Mateusz Kwasniewski 2024-09-25 12:56:09 +02:00 committed by GitHub
parent cdb1297246
commit e680921517
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -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);
}
});
});

View File

@ -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());