Async/Await in custom testEnvironment
See original GitHub issueAccording to the docs, a custom test environment can be setup this way:
const NodeEnvironment = require('jest-environment-node');
class CustomEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}
async setup() {
await super.setup();
await someSetupTasks();
this.global.someGlobalObject = createGlobalObject();
}
async teardown() {
this.global.someGlobalObject = destroyGlobalObject();
await someTeardownTasks();
await super.teardown();
}
runScript(script) {
return super.runScript(script);
}
}
But when I do that, I get the following errors
FAIL tests\user.test.js
● Test suite failed to run
D:\everest\tests\env.js:8
async setup() {
^^^^^
SyntaxError: Unexpected identifier
at node_modules/jest-runner/build/run_test.js:31:29
Code: env.js
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Async setup of environment with Jest - Stack Overflow
Based on current jest API constraints, you may choose to customize your test's runtime environment through the testEnvironment option.
Read more >Getting async/await to work in truffle JS tests
I installed truffle using "npm install truffle" yesterday. tests/MyToken.js: ... beforeEach(async function() { instance = await MyToken.new(); }); ...
Read more >State of Async/Await in JavaScript | by Keerti Kotaru
Async/await in JavaScript is syntactic sugar that simplifies writing code with promises. It is a two part implementation,. async : The async keyword...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
simple, flexible, fun. Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun....
Read more >ES6 async/await | Developer Guide - Nightwatch.js
The async function enables the API commands to return a promise and makes it possible to use the await operator to retrieve the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Your runtime has to support async-await (so use node 8 or newer) or you need to transpile.
PR welcome with a doc update highlighting that fact!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.