datahub/datahub-web-react/src/setupTests.ts
2024-03-26 17:18:54 -07:00

34 lines
1.2 KiB
TypeScript

// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/vitest';
// Mock window.matchMedia interface.
// See https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// and https://github.com/ant-design/ant-design/issues/21096.
global.matchMedia =
global.matchMedia ||
(() => {
return {
matches: false,
addListener: vi.fn(),
removeListener: vi.fn(),
};
});
window.location = { ...window.location, replace: () => {} };
// Suppress `Error: Not implemented: window.computedStyle(elt, pseudoElt)`.
// From https://github.com/vitest-dev/vitest/issues/2061
// and https://github.com/NickColley/jest-axe/issues/147#issuecomment-758804533
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);
vi.mock('js-cookie', () => ({
default: {
get: () => 'urn:li:corpuser:2',
},
}));
vi.mock('./app/entity/shared/tabs/Documentation/components/editor/Editor');