Jest: Error when testing async generator

Created on 22 Nov 2017  ·  3Comments  ·  Source: facebook/jest

This is a potential bug with jest / babel-jest

What is the current behavior?

Jest does not seem to support testing async generators.

Everything is explained on this repo I made for the occasion:

https://github.com/crubier/jest-bug

Setup

npm install

Problem

  • npm run test-no-jest succeeds, it runs the test without any test framework, just using asserts.
  • npm run test fails because of the async generator but it should not.

Error given by jest:

 FAIL  src/__tests__/basics.js
  ✕ async generator (1ms)

  ● async generator

    TypeError: iterable[Symbol.iterator] is not a function

      at _asyncIterator (src/__tests__/basics.js:3:421)
      at _callee2$ (src/__tests__/basics.js:36:138)
      at step (src/__tests__/basics.js:3:663)
      at src/__tests__/basics.js:3:893
          at Promise (<anonymous>)
      at Object.<anonymous> (src/__tests__/basics.js:3:574)
          at Promise (<anonymous>)
          at <anonymous>

My Configuration

See package.json in my repo

  • Mac OS High sierra
  • Node v8.6.0
  • NPM v 5.5.1
  • Babel-jest v21.2.0
  • Jest v21.2.1
Confirmed Help Wanted

Most helpful comment

Found a fix to this bug, but I believe it should be solved another way within babel-jest.

The solution was to require babel-polyfill from a Jest setupFile.

Here is the commit of the solution

https://github.com/crubier/jest-bug/commit/ea0fa2452e6d40d4e61cc0a412fcc341131ec718

All 3 comments

Found a fix to this bug, but I believe it should be solved another way within babel-jest.

The solution was to require babel-polyfill from a Jest setupFile.

Here is the commit of the solution

https://github.com/crubier/jest-bug/commit/ea0fa2452e6d40d4e61cc0a412fcc341131ec718

Hey @crubier @thymikee 👋
This is now fixed with babel 7.0.0-beta.41 🎉
I created a commit on a fork of your repo so you can see what changes you should do (in devDependencies & .babelrc). You'll need to upgrade to babel 7 and @babel/preset-env should be configured with shippedProposals and use-builtins.
https://github.com/yaelhe/jest-bug/commit/31bb5a10069a98ed1da58e13ee21c7d6fd782e97

Thank you @yaelhe!

Was this page helpful?
0 / 5 - 0 ratings