[Styles] add unit tests (#3557)

* unit tests for inspector styles feature
* add mock capability for local storage

Co-authored-by: Deep Tailor <deep.j.tailor@nasa.gov>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
David Tsay
2021-06-22 06:50:49 -07:00
committed by GitHub
parent 71392915c1
commit 7ca559fbe4
4 changed files with 456 additions and 0 deletions

View File

@ -0,0 +1,33 @@
export function mockLocalStorage() {
let store;
beforeEach(() => {
spyOn(Storage.prototype, 'getItem').and.callFake(getItem);
spyOn(Storage.prototype, 'setItem').and.callFake(setItem);
spyOn(Storage.prototype, 'removeItem').and.callFake(removeItem);
spyOn(Storage.prototype, 'clear').and.callFake(clear);
store = {};
function getItem(key) {
return store[key];
}
function setItem(key, value) {
store[key] = typeof value === 'string' ? value : JSON.stringify(value);
}
function removeItem(key) {
store[key] = undefined;
delete store[key];
}
function clear() {
store = {};
}
});
afterEach(() => {
store = undefined;
});
}