-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupJest.js
40 lines (34 loc) · 1.13 KB
/
setupJest.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
const chai = require('chai');
const sinonChai = require('sinon-chai');
const chaiAsPromised = require('chai-as-promised');
const chaiEnzyme = require('chai-enzyme');
const { configure } = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
chai.should();
chai.use(sinonChai);
chai.use(chaiAsPromised);
chai.use(chaiEnzyme());
configure({ adapter: new Adapter() });
// Make sure chai and jasmine ".not" play nice together
const originalNot = Object.getOwnPropertyDescriptor(chai.Assertion.prototype, 'not').get;
Object.defineProperty(chai.Assertion.prototype, 'not', {
get() {
Object.assign(this, this.assignedNot);
return originalNot.apply(this);
},
set(newNot) {
this.assignedNot = newNot;
return newNot;
}
});
// Combine both jest and chai matchers on expect
const jestExpect = global.expect;
global.expect = actual => {
const originalMatchers = jestExpect(actual);
const chaiMatchers = chai.expect(actual);
return Object.assign(chaiMatchers, originalMatchers);
};
// re-add jests expect.anything
if (jestExpect) {
global.expect.anything = jestExpect.anything;
}