1

I see many examples are happily using async/await in their JS tests, but it looks like mine doesn't seem to be using ES8? I'm not sure how to check.

I installed truffle using "npm install truffle" yesterday.

tests/MyToken.js:

...

beforeEach(async function() {
  instance = await MyToken.new();
});

...

Test output:

$ truffle test
Using network 'development'.

/Users/.../truffle/test/MyToken.js:13
  beforeEach(async function() {
             ^^^^^

SyntaxError: missing ) after argument list
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /Users/.../node_modules/mocha/lib/mocha.js:231:27
2

I figured it out after deciding to post additional details with the versions of truffle and node.

$ node --version
v6.11.5
$ truffle test
// no support for async

... install the latest node.

$ node --version
v8.9.0
$ truffle test
// async now works :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.