Reputation: 2403
How can I convert this function to use the async/await style:
it.only("should bump the 'minor' version attribute", () => {
const writeFile = util.promisify(require("fs").writeFile);
return writeFile("bump-minor.json", "contents").then(function() {
console.log('done');
});
});
I tried using this but it doesn't work:
const writeFile = util.promisify(require("fs").writeFile);
await writeFile("bump-minor.json", "contents");
console.log('done');
It shows the following error on line 2:
Parsing error: Unexpected token writeFile
If I add "async" to the mocha test function:
it.only("should bump the 'minor' version attribute", async () => {
const writeFile = util.promisify(require("fs").writeFile);
return writeFile("bump-minor.json", "contents").then(function() {
console.log('done');
});
});
Then I get this error on line 1:
Parsing error: Unexpected token =>
I'm probably missing some fundamental of how async/await and util.promisify works together in node
Using node 8.7.0.
Upvotes: 0
Views: 1894
Reputation: 2403
I was running eslint before mocha in "npm test":
"scripts": {
"test": "eslint *.js \"src/**/*.js\" \"test/**/*.js\" && mocha"
}
Removing the "eslint" call fixe the problem:
"scripts": {
"test": "mocha"
}
For some reason, eslint was failing async/await syntax with mocha
Upvotes: 1