-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"npm start" app works, "npm test" fails test with syntax error on export #4974
Comments
Hi! Why are you using ReactDOM to test? Take a look at Shallow Rendering, it's the recommended way to test components in React. I would recommend using Jest together with Enzyme |
Hi, Ricardo. I am not "using" ReactDOM . This is the way create-react-app comes out of the box. I am reporting a create-react-app bug. I expect, if i do nothing to cause a problem, that running I know i have not caused a problem because when i run Thanks for your comment, Ricardo. |
Hi Joe! Sorry, I think my comment came out a bit wrong, thanks for taking your time to submit the issue, I've been searching a bit and tested your repo, was able to reproduce the issue. Take a look at this this Jest issue, it seems babel-jest is not correctly transpiling ES6 features inside .mjs files. You can confirm that by changing the extension of your data file from .mjs to .js, and the test will pass. I see some workarounds are discussed in the comments, maybe you can comment there to see if you can something working out, not sure if it's an issue that it's being worked on. Good day Joe! |
Hi, SyntaxError: Unexpected token import “Unexpected token export” when running tests that use ES6 modules in node_modules directory #1294 |
You can View the Documentation of npm by viewing this link : https://docs.npmjs.com/all |
Dear Vinay, Nafis and Ricardo, Thanks to all of you. I have come around to testing again in my dev cycle. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue. |
Is this a bug report?
yes
Did you try recovering your dependencies?
yes
(Write your answer here.)
Which terms did you search for in User Guide?
(Write your answer here if relevant.)
Environment
PS ../gold-line-sac > npx create-react-app --info
Environment:
OS: Windows 10
Node: 10.9.0
Yarn: 1.9.4
npm: 6.2.0
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.1.0.0 AI-173.4819257
Packages: (wanted => installed)
react: ^16.4.2 => 16.4.2
react-dom: ^16.4.2 => 16.4.2
react-scripts: 1.1.5 => 1.1.5
PS ../gold-line-sac >
(paste the output of the command here)
Steps to Reproduce
(Write your steps here:)
notice app works importing testobj successfully. Browser displays:
'testob: '+JSON.stringify(testob)
testob: {"k1":"v1","k2":"v2","k3":"v3"}
PATH\gold-line-sac\src\m\gold-line-data.mjs:48
export const testobj = {"k1":"v1", "k2":"v2", "k3":"v3"};
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:73:7)
at Object. (src/App.js:9:194)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.83s
Ran all test suites.
Expected Behavior
I thought the test would pass
Actual Behavior
the test failed saying it encountered a syntax error:
PATH\gold-line-sac\src\m\gold-line-data.mjs:48
export const testobj = {"k1":"v1", "k2":"v2", "k3":"v3"};
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:73:7)
at Object. (src/App.js:9:194)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.83s
Ran all test suites.
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
Here is the Reproducible Demo Link
https://github.com/JoeCodeswell/react-test-prob-demo
Instructions to reproduce:
npm start
testobj
, etc successfully. Browser displays:'testob: '+JSON.stringify(testob)
testob: {"k1":"v1","k2":"v2","k3":"v3"}
npm test
npm start
command:The text was updated successfully, but these errors were encountered: