-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
React Native Testing docs/setup appears to be broken #6315
Comments
I build RN with Webpack and that too is devoid of tests. It'd be nice to see a focus on stabilization and encouraging best practices in the near future. |
cc @cpojer |
@jwhitley I'm sorry, you unfortunately hit an issue with a transitive dependency that broke Jest yesterday. We just published a major update to Jest and redid the entire website ( http://facebook.github.io/jest/ ) on Friday as well and I'm currently rewriting the react-native documentation for Jest. Deleting Now that Jest 0.9.0 is done I will focus my efforts on improving Jest support for react-native, and as you suggested, we will include it in |
Awesome stuff @cpojer :) ✋ |
To unblock you, I recommend installing jest-cli 0.9.0 and babel-jest 9.0.1 with the babel-preset-react-native. See the Getting Started guide of Jest on how that works: http://facebook.github.io/jest/docs/getting-started.html#content please also remove the scriptPreprocessor in your Jest config, which is not needed any longer if you are using babel-jest. I'll keep this issue open until I'm done rewriting the documentation both for react-native and until I added better documentation on RN testing to the Jest website. The react-native init work is tracked separately. |
@cpojer Brilliant, that nails it. ❤️ I've pushed one additional commit to the sample repo mentioned above which applies your configuration changes. Do you happen to know if there's a PR with corresponding updates to Testing.md in flight? If there is, I'll go review it. If not, I'd be happy to submit one to help out. |
Hey! Nothing yet (it's Sunday after all ;) ) but if you'd like to contribute a page on how to set up React-Native testing with Jest, that would be fantastic! I'm thinking of adding it to the Jest repo, see https://github.com/facebook/jest – the setup is the same as here, so just change the docs, |
+1 for adding docs about testing in React-Native ! |
Hi There, Has there been any changes on this? I am still getting mixed results using babel-jest and the react-native jest support. Ciaran |
Can you tell what's causing this error:
Here's my package.json
My test file:
BTW - if I use
|
Thank you for your patience. We launched Jest 14.0 with experimental react-native support: Please feel free to create new issues after trying out the new integration if any issues remain. |
tl;dr: Setting up and running tests for a new React Native project appears to be broken when following the official documentation. The error received is at least superficially similar to #3999.
Repro steps
npm install -g react-native-cli
react-native install ReactNativeTesting
cd ReactNativeTesting
Now, following the instructions RN Testing docs (@ 0.21) and Jest Getting Started:
npm install --save-dev jest-cli
package.json
per the Testing docs.sum.js
file from Jest Getting started to the project root.sum-test.js
file to<rootDir>/__tests__
npm test
Actual results
Platform notes
React Native 0.20.0 and 0.21.0
node v5.5.0 (npm v3.3.12) and node v5.7.0 (npm v3.6.0)
Platform: OS X 10.11.3
Sample repo
I've created a sample repo with the major steps (r-n init, testing config, etc.) broken into separate commits. Please see jwhitley/ReactNativeTesting.
Notes
This sample does about the simplest thing possible in terms of its code. No ES6+, no
import
, no import/require ofreact-native
(cf. #700), and so forth. Yet it's still breaking hard. There are very few public RN projects that appear to use any testing whatsoever, and each of those appears to have some different, cobbled-together solution to get tests running. Heck, I ran into one today trying to sort out my own First Test issues that had previously working tests and broke with this error. See benoitvallon/react-native-nw-react-calculator#22 for the PR that nominally fixed the issue for that repo. A similar change (jesttestPathDirs
and adding arn-cli.config.js
with a custom blacklist) wasn't ultimately effective in my case.It seems that the official process for setting up and getting to First Test should, at minimum, be something that runs as a CI job against this repo. (e.g. using something similar to the repro steps outlined here.) Being unable to get any tests running is particularly frustrating.
Going a step further, as RN matures, I'd suggest baking in support for basic test setup into
react-native init
, preferably by default, possibly including an option to disable test scaffolding generation.The text was updated successfully, but these errors were encountered: