-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-boot.js
executable file
·63 lines (54 loc) · 1.39 KB
/
test-boot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import chai from 'chai';
import sinonChai from 'sinon-chai';
import chaiAsPromised from 'chai-as-promised';
import { jsdom } from 'jsdom';
chai.use(chaiAsPromised);
chai.use(sinonChai);
const exposedProperties = ['window', 'navigator', 'document'];
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js',
};
// spec/javascripts/helpers/jest-env.js
// window.getSelection isn't in jsdom
// https://github.com/tmpvar/jsdom/issues/937
window.getSelection = function() {
return {
addRange: function() {},
removeAllRanges:function() {}
};
};
window.document.getSelection = window.getSelection;
// Storage Mock
function storageMock() {
const storage = {};
return {
setItem(key, value) {
storage[key] = value || '';
},
getItem(key) {
return storage[key] || null;
},
removeItem(key) {
delete storage[key];
},
get length() {
return Object.keys(storage).length;
},
key(i) {
const keys = Object.keys(storage);
return keys[i] || null;
},
};
}
// mock the localStorage
global.localStorage = storageMock();
// mock the sessionStorage
global.sessionStorage = storageMock();