Search code examples
ava

Ava js not working async await tests


I am trying to use Ava.js for my tests but actually I can't launch async/await. I just copy/paste an example from documentation and it showed to me an error.

(async function(t) {
SyntaxError: missing) after argument list.

looks like it not compiled correctly and I don't know what I did wrong. Could someone help me please?

Here is my code

test.spec.js

import test from 'ava';

test(async t => {
    const value = await promiseFn();
    t.true(value);
});

package.json

{
  "scripts": {
    "test": "ava"
  },
  "devDependencies": {
    "ava": "^0.16.0",
    "ava-spec": "^1.0.1",
    "babel-preset-es2015": "^6.18.0",
    "tap-nyan": "0.0.2"
  },
  "ava": {
    "babel": "inherit",
    "require": [
      "babel-register"
    ]
  }
}

and .babelrc

{
  "presets": [
    "es2015"
  ]
}

Solution

  • async/await are not transpiled using the preset es2015.
    You should enable the preset es2017 or latest.

    Another solution is to run your test suite on Node v7 since it natively support async/await.