question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests fail with `async`

See original GitHub issue

Not completely sure this is an issue of this repo, could be a jest’s one. I’m reporting it here because it could be a configuration problem.

Description

Running npm test fails when using async/await.

Expected behavior

The test runs

Actual behavior

I receive an error:

  ● Test suite failed to run

    /src/merchants.js: Expected type "Expression" with option {}
      
      at Object.t.(anonymous function) [as assertExpression] (node_modules/babel-types/lib/index.js:362:13)
      at Array.forEach (native)

Environment

Run these commands in the project folder and fill in their results:

  • npm ls react-scripts: v0.8.1

  • node -v: v6.9.1

  • npm -v: v3.10.8

  • Operating system: Fedora 24

  • Browser and version: –

Reproducible Demo

Just a new “cra” project, with an async/await function tested.

I have a demonstration here, just git clone, npm install and npm test.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
existentialismcommented, Dec 6, 2016

@EnoahNetzach I’ll try and take a look at this later tonight as well

1reaction
EnoahNetzachcommented, Dec 5, 2016

The result I get from babel-preset-env is that I need:


check-es2015-constants: false
syntax-trailing-function-commas: true
transform-async-to-generator: true
transform-es2015-arrow-functions: false
transform-es2015-block-scoped-functions: false
transform-es2015-block-scoping: false
transform-es2015-classes: false
transform-es2015-computed-properties: false
transform-es2015-destructuring: false
transform-es2015-for-of: false
transform-es2015-function-name: false
transform-es2015-literals: false
transform-es2015-object-super: false
transform-es2015-parameters: false
transform-es2015-shorthand-properties: false
transform-es2015-spread: false
transform-es2015-sticky-regex: false
transform-es2015-template-literals: false
transform-es2015-typeof-symbol: false
transform-es2015-unicode-regex: false
transform-exponentiation-operator: true
transform-regenerator: false

I’ll try to reintroduce them one by one…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Asynchronous Code - Jest
When you have code that runs asynchronously, Jest needs to know when the code it is ... test('the fetch fails with an error',...
Read more >
Testing-library: avoid these mistakes in async tests
Sometimes, tests start to unexpectedly fail even if no changes were made to the business logic. It may happen after e.g. you updated...
Read more >
Why isn't this unit test catching an error from this async/await ...
In this case, we call the fetchItem() function with an argument that is not a string (which our database query will expect). It's...
Read more >
jest test async function fail - Stack Overflow
I have a simple typescript function which just prints some text and sleep. The test finished without waiting for the async ...
Read more >
How to Test Asynchronous Methods with React Testing Library
There are two things you want to test when it comes to asynchronous methods. The first is that the method itself got called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found