fleet/frontend/.test.setup.js

60 строки
1.2 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import nock from 'nock';
2016-09-06 21:41:16 +03:00
import jsdom from 'jsdom';
nock.disableNetConnect()
configure({ adapter: new Adapter() });
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;
global.document.queryCommandEnabled = () => { return true; };
global.document.execCommand = () => { return true; };
2016-09-06 21:41:16 +03:00
global.window = doc.defaultView;
global.window.getSelection = () => {
return {
removeAllRanges: () => { return true; },
};
};
2016-09-06 21:41:16 +03:00
global.navigator = global.window.navigator;
function mockStorage() {
let 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;
},
clear () {
storage = {};
},
};
}
global.localStorage = window.localStorage = mockStorage();