test: Silence the DOM dump in test output

This silences the DOM dump logged into test output by testing-library while keeping all the relevant information about the test failure in the output.
This commit is contained in:
regexowl 2024-07-17 15:06:24 +02:00 committed by Ondřej Ezr
parent e2397b90d4
commit 4e24dc35b6

View file

@ -1,3 +1,4 @@
import { configure } from '@testing-library/react';
import nodeFetch, { Request, Response } from 'node-fetch';
import { server } from './mocks/server';
@ -16,6 +17,16 @@ const MockResizeObserver = vi.fn(() => ({
}));
vi.stubGlobal('ResizeObserver', MockResizeObserver);
// Remove DOM dump from the testing-library output
configure({
getElementError: (message: string) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = '';
return error;
},
});
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
afterAll(() => server.close());
afterEach(() => server.resetHandlers());