2016-09-06 21:41:16 +03:00
|
|
|
import jsdom from 'jsdom';
|
|
|
|
|
|
|
|
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
|
|
|
|
|
|
|
|
global.document = doc;
|
|
|
|
global.window = doc.defaultView;
|
|
|
|
global.navigator = global.window.navigator;
|
2016-09-13 22:50:37 +03:00
|
|
|
|
|
|
|
function mockStorage() {
|
|
|
|
const storage = {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
setItem(key, value = '') {
|
|
|
|
storage[key] = value;
|
|
|
|
},
|
|
|
|
getItem(key) {
|
|
|
|
return storage[key];
|
|
|
|
},
|
|
|
|
removeItem(key) {
|
|
|
|
delete storage[key];
|
|
|
|
},
|
|
|
|
get length() {
|
|
|
|
return Object.keys(storage).length;
|
|
|
|
},
|
|
|
|
key(i) {
|
|
|
|
return Object.keys(storage)[i] || null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
global.localStorage = window.localStorage = mockStorage();
|