Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Created July 12, 2022 07:32
Show Gist options
  • Save AvocadoVenom/dc38bee871196f8196f2c1c3901e322a to your computer and use it in GitHub Desktop.
Save AvocadoVenom/dc38bee871196f8196f2c1c3901e322a to your computer and use it in GitHub Desktop.
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
}))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment