1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-26 11:49:04 +01:00
blog/.jest/__mocks__/matchMedia.ts

28 lines
758 B
TypeScript
Raw Normal View History

2022-11-19 16:09:13 +01:00
const matchMediaMock = Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest
.fn()
.mockImplementationOnce((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
}))
.mockImplementation((query) => ({
matches: true,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
}))
})
export default matchMediaMock