-
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
[JS: Testing] require('react-native') and jest test fails #700
Comments
Related StackOverflow question with some more research: How to use Jest with React Native |
The main reason for this issue is that we currently ship React in source form ( In the mean time here is what you can do: adapt the |
I'm actually still getting errors after using the I haven't seen any of the tests in this repo do that yet, so I'm assuming it isn't supported yet. @amasad can you confirm? |
You have to mock react-native. The following example works: jest.setMock('react-native', {
NativeModules: {}
});
jest.dontMock('../js/model/DropBox');
jest.dontMock('mori');
var mori = require('mori')
describe('loadFiles', function() {
pit('Spec 1', function() {
var DropBox = require('../js/model/DropBox');
var dropBox = new DropBox({
load: function(callback) {
callback(false,
["file1"],
['{"value":1}'])}
});
return dropBox.loadFiles().then(
function(stuff) {
var result = mori.toJs(stuff);
expect(result.length).toBe(1);
});
});
}); |
I think we need a section in the docs about how to test your React Native components |
@brentvatne I'd be glad to help if you guys think the approach here is satisfactory. naoufal/react-native-progress-hud#1 |
@naoufal - that would be great! can you write up a draft for that and submit a PR? I'll review and augment as necessary |
Sure — I'll try and submit a PR tomorrow. |
@brentvatne PR submitted #1477. Can you review/leave feedback? |
I'm getting problems with react-natives special requires
|
Does anybody managed to get auto mocked |
cc @cpojer |
Any update on this issue? I'm looking for a straight forward way of testing components. Cheers.. |
I'm currently polishing up the release for 0.9.0 which should improve the babel support in Jest and will fix performance. The next step will be to improve mocking of react-native by a lot. |
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. |
I have the following simple Module
and the following test:
I know that the test is nonsense, but I just want to make sure that my setup works. Running npm test gives:
at /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/core/ReactUpdates.js:26:39
at /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/core/ReactUpdateQueue.js:18:20
at /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/modern/class/ReactComponent.js:14:24
at /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/browser/ui/React.js:18:22
at /Users/roger/Documents/AwesomeProject/node_modules/react-native/Libraries/react-native/react-native.js:20:47
The text was updated successfully, but these errors were encountered: