Skip to content

Instantly share code, notes, and snippets.

@sketchbuch
Last active January 24, 2020 07:06
Show Gist options
  • Save sketchbuch/fd2d3a63884117119c7433ed3f3c5a4a to your computer and use it in GitHub Desktop.
Save sketchbuch/fd2d3a63884117119c7433ed3f3c5a4a to your computer and use it in GitHub Desktop.
TESTING - How to mock window properties in Jest
// Store original value to set back after tests
const previousInnerWidth = window.innerWidth
Object.defineProperty(window, 'innerWidth', {
configurable: true,
value: 400,
writable: true,
})
// Expect what you want...
// Restore original value
Object.defineProperty(window, 'innerWidth', {
configurable: true,
value: previousInnerWidth,
writable: true,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment