Created
April 17, 2018 21:41
-
-
Save nerdic-coder/ab1738348f762fd8e2bb263f5fdd4ce2 to your computer and use it in GitHub Desktop.
Example of jestGlobalMocks.ts
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
const mock = () => { | |
let storage = {}; | |
return { | |
getItem: key => key in storage ? storage[key] : null, | |
setItem: (key, value) => storage[key] = value || '', | |
removeItem: key => delete storage[key], | |
clear: () => storage = {}, | |
}; | |
}; | |
Object.defineProperty(window, 'localStorage', {value: mock()}); | |
Object.defineProperty(window, 'sessionStorage', {value: mock()}); | |
Object.defineProperty(window, 'getComputedStyle', { | |
value: () => ['-webkit-appearance'] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment