forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestHelper.js
39 lines (32 loc) · 895 Bytes
/
testHelper.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
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import jsdom from 'jsdom/lib/old-api';
import chai from 'chai';
import chaiImmutable from 'chai-immutable';
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
const win = doc.defaultView;
global.document = doc;
global.window = win;
// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal(window) {
Object.keys(window).forEach((key) => {
if (key in global) return;
global[key] = window[key];
});
}
// take all properties of the window object and also attach it to the
// mocha global object
propagateToGlobal(win);
// everything we need for our tests
const {
assert, expect,
} = chai;
chai.use(chaiImmutable);
export {
React,
chai,
assert,
expect,
TestUtils,
};