31 lines
737 B
TypeScript
31 lines
737 B
TypeScript
type MatchMediaProps = Partial<{
|
|
matches: boolean;
|
|
media: string;
|
|
onchange: null;
|
|
addListener: jest.Mock;
|
|
removeListener: jest.Mock;
|
|
addEventListener: jest.Mock;
|
|
removeEventListener: jest.Mock;
|
|
dispatchEvent: jest.Mock;
|
|
}>;
|
|
|
|
const createMatchMedia = (props: MatchMediaProps) => {
|
|
return jest.fn((query) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
...props,
|
|
}));
|
|
};
|
|
|
|
Object.defineProperty(window, 'scrollTo', jest.fn());
|
|
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: createMatchMedia({ matches: true }),
|
|
});
|