Async Iterators or generators simply don't work with jest even thought they're natively supported in Node 10
cd to a test project where jest worksasync function* foo() {} to some fileyarn start or node index.js etc.)yarn test*"The test suite should run normally and not throw this error
Seems like repl.it doesn't have node 10. Sorry :/
Issues without a reproduction link are likely to stall.
npx envinfo --preset jestPaste the results here:
npx: installed 1 in 1.672s
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 10.3.0 - ~/.nvm/versions/node/v10.3.0/bin/node
Yarn: 1.7.0 - ~/.yarn/bin/yarn
npm: 6.1.0 - ~/.nvm/versions/node/v10.3.0/bin/npm
@pranaygp tried testing async function on node 10.5.0 and it is working fine.
Here is one example to test generator function:

@ASHISH932 I'm dealing with the exact same case as @pranaygp described and it or no it doesn't make a difference. I get that unexpected token * no matter what.
I've been able to get this working by:
.babelrc in my project.{
"plugins": ["syntax-async-generators"]
}
babel-plugin-syntax-async-generators bynpm install babel-plugin-syntax-async-generators --save-dev
After that, I got expected behavior. Having said that, I think that if those async generators and async iteration are natively supported by node starting from 10.5.0 tools like jest should support them out of box as well.
@nooga you should be using env preset of babel(babel-preset-env) as it's support latest javascript feature, whenever it's get official . Here is an article to set up your react environment.
@ASHISH932 Thanks, although I don't use babel in my project directly and it has absolutely nothing to do with react.
@nooga that's up to you to decide architecture of your project but if you read documentation of jest they have mentioned to use env preset
@ASHISH932, I am using node 10.5. Still getting the error after I added a .babelrc.js (below). How do you suggest using babel-preset-env?
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
}
]
]
}
EDIT
Possibly related to the fact that I am using ts-jest, which skips babel -- https://github.com/kulshekhar/ts-jest/issues/471#issuecomment-375739463
AFAIK this should work without babel if node accepts without babel.
Node does support async generators starting from version 10.3.
So jest _should_ work without any babel configuration on latest node.
@shaunc if you are using babel this comment https://github.com/facebook/jest/issues/4936#issuecomment-373772896 might be helpful for you
This is essentially the same issue as #6829.
tl;dr: Jest uses babel by default, so you have to tell it to understand your syntax or explicitly disable babel.
You can follow https://github.com/babel/babel/issues/7660 for what I think is the correct solution to this problem
@SimenB in https://github.com/kulshekhar/ts-jest/issues/471 the problem is that ts-jest passes typescript compiler results to jest without using babel by default. So
or explicitly disable babel.
doesn't actually work, but it should
That's something that should be addressed in ts-jest then.
Remember that Babel is needed for code coverage, though.
Most helpful comment
I've been able to get this working by:
.babelrcin my project.babel-plugin-syntax-async-generatorsbyAfter that, I got expected behavior. Having said that, I think that if those async generators and async iteration are natively supported by node starting from 10.5.0 tools like jest should support them out of box as well.