forked from wallabyjs/wallaby-webpack-es6-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
75 lines (60 loc) · 1.83 KB
/
setup.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
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
import 'babel-polyfill';
import expect from 'expect';
import expectJSX from 'expect-jsx';
import { jsdom } from 'jsdom';
require('babel-core/register')({
ignore: /node_modules\/(?!quill)/
});
global.document = jsdom('<!doctype html><html><body></body></html>');
global.window = document.defaultView;
global.location = {
protocol: 'http'
};
global.window.__testing__ = true;
global.alert = (msg) => msg;
global.VERSION = 1;
global.window.performance = Date;
global.window.requestAnimationFrame = () => 0;
global.window.cancelAnimationFrame = () => false;
global.Node = {};
const noop = () => 1;
require.extensions['.svg'] = noop;
const exposedProperties = ['window', 'navigator', 'document'];
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
// global.navigator = global.window.navigator;
global.navigator = {
userAgent: 'node.js'
};
import StorageShim from 'node-storage-shim';
window.localStorage = new StorageShim();
expect.extend(expectJSX);
expect.extend({
toBeCloseTo(value, precision = 2, message) {
expect.assert(
typeof this.actual === 'number',
'The "actual" argument in expect(actual).toBeCloseTo() must be a number'
);
expect.assert(
typeof value === 'number',
'The "value" argument in toBeCloseTo(value) must be a number'
);
expect.assert(
typeof precision === 'number',
'The "precision" argument in toBeCloseTo(value, precision) must be a number'
);
const close = Math.abs(value - this.actual) < (Math.pow(10, -precision) / 2);
expect.assert(
close,
(message || 'Expected %s to be within %s decimal places of %s'),
this.actual,
precision,
value
);
}
});