I am trying to create a custom test environment with Jest as described in their official docs
Unfortunately I get the following error:
Determining test suites to run...
FAIL acceptancetests/mongo.test.js
● Test suite failed to runTypeError: TestEnvironment is not a constructor
at ../node_modules/jest-runner/build/run_test.js:88:25
My test is completely empty and my CustomTestEnvironment just calls the super classes. I am on the latest Jest version (24.3.1)
I think it is very weird, that the error is thrown within the Jest library.
This is my test-environment.js:
const NodeEnvironment = require('jest-environment-node');
class CustomEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}
async setup() {
await super.setup();
}
async teardown() {
await super.teardown();
}
runScript(script) {
return super.runScript(script);
}
}
Any help is appreciated!
Ok, this is a silly problem and I found the solution.
I had to export the CustomEnvironment
const NodeEnvironment = require('jest-environment-node');
class CustomEnvironment extends NodeEnvironment {
...
}
module.exports = CustomEnvironment
And also add it in the jest.config.js
const { defaults } = require("jest-config");
module.exports = {
testEnvironment: './../CustomEnvironment.js',
};
I don't know why the guide doesn't include that line :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With