diff --git a/frontend/src/setupTests.ts b/frontend/src/setupTests.ts index 0018fca294..870c883bfd 100644 --- a/frontend/src/setupTests.ts +++ b/frontend/src/setupTests.ts @@ -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); + } + }); });