Skip to content

Commit

Permalink
chore: silence remaining front end test warnings (#8465)
Browse files Browse the repository at this point in the history
This silences front end test warnings, errors, and logs that we don't
care about. The
reason we don't care is that:
- we won't fix
- it's test-specific, doesn't appear to happen in real life

And it clogs the test logs.
  • Loading branch information
thomasheartman authored Oct 17, 2024
1 parent d5ddbdd commit bb22210
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,40 @@ if (!window.ResizeObserver) {

process.env.TZ = 'UTC';

const errorsToIgnore = [
'Warning: An update to %s inside a test was not wrapped in act',
"Failed to create chart: can't acquire context from the given item",
];

const warningsToIgnore = [
'[MSW] Found a redundant usage of query parameters in the request handler URL for',
'MUI: You have provided an out-of-range value',
];

const logsToIgnore = ['An exception was caught and handled.'];

// ignore known React warnings
const consoleError = console.error;
const consoleWarn = console.warn;
const consoleLog = console.log;
beforeAll(() => {
const shouldIgnore = (messagesToIgnore: string[], args: any[]) =>
typeof args[0] === 'string' &&
messagesToIgnore.some((msg) => args[0].includes(msg));

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',
)
)
) {
if (!shouldIgnore(errorsToIgnore, args)) {
consoleError(...args);
}
});
vi.spyOn(console, 'warn').mockImplementation((...args) => {
if (!shouldIgnore(warningsToIgnore, args)) {
consoleWarn(...args);
}
});
vi.spyOn(console, 'log').mockImplementation((...args) => {
if (!shouldIgnore(logsToIgnore, args)) {
consoleLog(...args);
}
});
});

0 comments on commit bb22210

Please sign in to comment.