Skip to content
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

SyntaxError: Unexpected token ... when run jest tests #5532

Closed
maksimr opened this issue Jan 25, 2016 · 9 comments
Closed

SyntaxError: Unexpected token ... when run jest tests #5532

maksimr opened this issue Jan 25, 2016 · 9 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@maksimr
Copy link
Contributor

maksimr commented Jan 25, 2016

I try run tests for react-native but seems jest does not play well with ES6
Jest configuration - https://github.com/maksimr/TestAndroid/blob/test-jest/package.json#L10-L27
Test - https://github.com/maksimr/TestAndroid/blob/test-jest/js/components/HelloWorld/__tests__/index-test.js

Module - https://github.com/maksimr/TestAndroid/blob/test-jest/js/components/HelloWorld/index.js

run npm test take

Using Jest CLI v0.8.2, jasmine2
 FAIL  js/components/HelloWorld/__tests__/index-test.js
● Runtime Error
SyntaxError: Unexpected token ...
npm ERR! Test failed.  See above for more details.

Error message is not so clear but problem in import and I assume problem with es6
How can I run tests for react-native's es6 code?

Thanks

node --version
v5.4.1

npm --version
3.5.3

@facebook-github-bot
Copy link
Contributor

Hey maksimr, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

@mpm
Copy link

mpm commented Jan 26, 2016

I have the same issue. I don't understand much of the whole babel transformation pipeline, but if you open the preprocessor.js refrenced in your package.json, you will see that files from the node_modules subdirectory are excempted from beeing transformed to ES5 (see link, line 19):

That means the contents of the react-native npm package is not transformed, while it uses the spread operator in the main file in line 114.

(I found this by removing all calls to require so I know it happens when you require the react-native package).

I have no idea what this all means or what the intention for this code was (it was introduced a couple of releases ago already), but so far just commenting out the whole conditional block in preprocessor.js line 19+ works for me!

@maksimr
Copy link
Contributor Author

maksimr commented Jan 27, 2016

@mpm thanks! You are right! Problem reproduce only if we import react-native

I close this issue because it's duplicate of #700

@maksimr maksimr closed this as completed Jan 27, 2016
@vitalets
Copy link

Even after commenting lines in preprocessor.js I'm getting another error whet trying to require react-native:

const React = require('react-native');
console.log(React); // TypeError: Cannot read property 'DEFINE_MANY' of undefined

@maksimr
Copy link
Contributor Author

maksimr commented Jan 27, 2016

@vitalets maybe you should disable jest automock or add some react libraries to unmockedModulePathPatterns:

    "unmockedModulePathPatterns": [
      "promise",
      "source-map",
      "<rootDir>/node_modules/react",
      "<rootDir>/node_modules/fbjs",
      "<rootDir>/node_modules/react-dom",
      "<rootDir>/node_modules/react-addons-test-utils"
    ]

@vitalets
Copy link

thanks @maksimr! I will try.
But if I disable jest automock I loose the most powerfull feature of jest..
And I will need to write manual mocks for all used rn api

@lovelydreamer
Copy link

I'm having this same issue and can't solve it. Suggestions appreciated.
https://stackoverflow.com/questions/36993445/runtime-error-running-jest-in-react

@buamod
Copy link

buamod commented Sep 26, 2017

I having the same issue

@miclovich
Copy link

same here. With react16+

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants