0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-03 21:48:55 -05:00
logto/packages/ui/src/jest.setup.ts

35 lines
920 B
TypeScript
Raw Normal View History

import { Crypto } from '@peculiar/webcrypto';
2021-08-02 23:45:55 +08:00
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
2021-08-02 23:45:55 +08:00
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
// eslint-disable-next-line @silverhand/fp/no-mutation
global.crypto = new Crypto();
const translation = (key: string) => key;
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: translation,
i18n: {
t: translation,
},
}),
}));
2021-08-02 23:45:55 +08:00
export {};