mirror of
https://github.com/nasa/openmct.git
synced 2025-06-18 07:08:12 +00:00
[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:
33
src/utils/testing/mockLocalStorage.js
Normal file
33
src/utils/testing/mockLocalStorage.js
Normal 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;
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user