2016-09-06 21:41:16 +03:00
|
|
|
import jsdom from 'jsdom';
|
|
|
|
|
2016-10-11 19:10:41 +03:00
|
|
|
const doc = jsdom.jsdom(
|
|
|
|
`<!doctype html>
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<input id="method1" value="hello world" />
|
|
|
|
<input id="method2" value="hello world" />
|
|
|
|
</body>
|
|
|
|
</html>`,
|
|
|
|
{
|
|
|
|
url: 'http://localhost:8080/foo'
|
|
|
|
},
|
|
|
|
);
|
2016-09-06 21:41:16 +03:00
|
|
|
|
|
|
|
global.document = doc;
|
2016-10-11 19:10:41 +03:00
|
|
|
global.document.queryCommandEnabled = () => { return true; };
|
|
|
|
global.document.execCommand = () => { return true; };
|
2016-09-06 21:41:16 +03:00
|
|
|
global.window = doc.defaultView;
|
2016-10-11 19:10:41 +03:00
|
|
|
global.window.getSelection = () => {
|
|
|
|
return {
|
|
|
|
removeAllRanges: () => { return true; },
|
|
|
|
};
|
|
|
|
};
|
2016-09-06 21:41:16 +03:00
|
|
|
global.navigator = global.window.navigator;
|
2016-09-13 22:50:37 +03:00
|
|
|
|
|
|
|
function mockStorage() {
|
2016-09-20 02:43:35 +03:00
|
|
|
let storage = {};
|
2016-09-13 22:50:37 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
2016-09-20 02:43:35 +03:00
|
|
|
clear () {
|
|
|
|
storage = {};
|
|
|
|
},
|
2016-09-13 22:50:37 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
global.localStorage = window.localStorage = mockStorage();
|