-
-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathjest-custom-environment.js
More file actions
26 lines (22 loc) · 802 Bytes
/
jest-custom-environment.js
File metadata and controls
26 lines (22 loc) · 802 Bytes
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
const { TestEnvironment } = require('jest-environment-node');
class JestCustomEnvironment extends TestEnvironment {
constructor(config) {
super(config);
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
}
async setup() {
await super.setup();
// Workaround for this bug https://github.com/facebook/jest/issues/2549
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
Object.defineProperty(this.global.Error, Symbol.hasInstance, {
value: target => target instanceof Error || this.jestErrorHasInstance(target),
});
}
async tearDown() {
Object.defineProperty(this.global.Error, Symbol.hasInstance, {
value: this.jestErrorHasInstance,
});
await super.tearDown();
}
}
module.exports = JestCustomEnvironment;