Created
November 10, 2017 01:32
-
-
Save derekshi/06677e16f41e584175ad7dee7dc6e82c to your computer and use it in GitHub Desktop.
Some mock objects for Angular projects using Jest testing framework
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(document, 'doctype', { | |
value: '<!DOCTYPE html>' | |
}); | |
Object.defineProperty(window, 'getComputedStyle', { | |
value: () => { | |
return { | |
display: 'none', | |
appearance: ['-webkit-appearance'] | |
}; | |
} | |
}); | |
Object.defineProperty(window, 'CSS', {value: mock()}); | |
Object.defineProperty(window, 'requestAnimationFrame', {value: () => {} }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment