Jest test failing
See original GitHub issueIssue 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
- create-react-app my-app --scripts-version=react-scripts-ts
- npm install --save reactstrap@5.0.0-beta.2 @types/reactstrap
- import and use any reactstrap component to App.ts, for ex. Container
- 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:
- Created 6 years ago
- Reactions:11
- Comments:10 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Quick fix - revert to “reactstrap”: “5.0.0-beta”. It has older react-popper version.
The PR in react-popper has been merged, just waiting on it to be published in a release.