Last active
January 24, 2020 07:06
-
-
Save sketchbuch/fd2d3a63884117119c7433ed3f3c5a4a to your computer and use it in GitHub Desktop.
TESTING - How to mock window properties in Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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