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
1

2 Answers 2

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
0

With node 8, async/await was enabled by default. Prior to version 7.6 you could use async/await as long as you added the --harmony-async-await flag. For version prior you could also use Babel to transpile down to ES5 compatible javascript. I suggest installing Node 8 or above .

Node ≥ 7.6 confirm by entering node -v in a command line npm ≥ 4 confirm by entering npm -v in command line Truffle ≥ 3.3 confirm by entering truffle -v in command line Ganache-cli ≥ 5.0.0 confirm by entering ganache-cli -v in command line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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