-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
testHelper.js
32 lines (25 loc) · 931 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
import chai from 'chai';
import dirtyChai from 'dirty-chai';
import hook from 'css-modules-require-hook';
import { jsdom } from 'jsdom';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
process.env.NODE_ENV = 'test';
hook({
generateScopedName: '[name]__[local]___[hash:base64:5]',
});
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];
}
});
Enzyme.configure({ adapter: new Adapter() });
// chaiEnzyme needs to be initialised here, so that canUseDOM is set
// to true when react-dom initialises (which chai-enzyme depends upon)
const chaiEnzyme = require('chai-enzyme');
chai.use(dirtyChai);
chai.use(chaiEnzyme());