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.

Jest test failing

See original GitHub issue

Issue description

  • components: any
  • reactstrap version #5.0.0-beta.2
  • import method es(typescript) (if umd, are you using the “full” version (only for v5+)?)
  • react version #16.2.0

What is happening?

Any Jest test in app created by create-react-app fail to run.

Steps to reproduce issue

  1. create-react-app my-app --scripts-version=react-scripts-ts
  2. npm install --save reactstrap@5.0.0-beta.2 @types/reactstrap
  3. import and use any reactstrap component to App.ts, for ex. Container
  4. npm run test

Error message in console

  ● Test suite failed to run

    C:\temp\my-app\node_modules\react-popper\lib\react-popper.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as Manager } from './Manager';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (node_modules/reactstrap/dist/reactstrap.cjs.js:14:19)
      at Object.<anonymous> (src/App.tsx:15:20)

I don’t think the reason is typescript. As I understood, Jest runs as node process, and create-react-app setup jest to not transpile any files under node_modules folder. Since react-popper/package.json conains "main": "lib/react-popper.js", and version under /lib contains es6’ export statements, node finally gets those export statements and fails. If I change react-popper/package.json to point main to dist: "main": "dist/react-popper.js", tests pass.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
sinxwalcommented, Feb 28, 2018

Quick fix - revert to “reactstrap”: “5.0.0-beta”. It has older react-popper version.

8reactions
TheSharpieOnecommented, Mar 15, 2018

The PR in react-popper has been merged, just waiting on it to be published in a release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Jest, how can I make a test fail? - Stack Overflow
Method-1. You can wrap your promise function within expect and tell jest the function should reject with the given error. If the someOperation() ......
Read more >
Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​. Try using the debugging support built into...
Read more >
How to debug failing tests in jest - DEV Community ‍ ‍
Quick tip for debugging failing tests with jest. If you already know why would you want to run tests with the debugger you...
Read more >
Jest explicitly or arbitrarily force fail() a test - Code with Hugo
Output of the test run shows that if the code doens't throw, the test suite will fail, which is desired behaviour: FAIL src/fail-throws- ......
Read more >
How to find the root cause of a failing test if Jest doesn't tell ...
How to find the root cause of a failing test if Jest doesn't tell you what's wrong. Debugging tests can be hard —...
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