[JS: Testing] require('react-native') and jest test fails
See original GitHub issueI have the following simple Module
/**
* @providesModule DropBox
* @flow
*/
'use strict';
var React = require('react-native');
var {
NativeModules,
} = React;
var _ = require('underscore')._;
class DropBox {
constructor() {
this.nativeModule = NativeModule.DropBox;
}
loadFiles() {
return new Promise((resolve, reject) => {
this.nativeModule.load((error, names, contents) => {
if (error) {
reject(error);
} else {
var parsedContent = contents.map((c) => {
return JSON.parse(c);
});
resolve(_.zip(names, parsedContent));
}
});
})
}
}
module.exports = DropBox;
and the following test:
jest.dontMock('../js/model/DropBox');
describe('loadFiles', function() {
it('adds 1 + 2 to equal 3', function() {
var DropBox = require('../js/model/DropBox');
expect(1 + 21).toBe(3);
});
});
I know that the test is nonsense, but I just want to make sure that my setup works. Running npm test gives:
- TypeError: /Users/roger/Documents/AwesomeProject/js/model/DropBox.js: /Users/roger/Documents/AwesomeProject/node_modules/react-native/Libraries/react-native/react-native.js: /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/browser/ui/React.js: /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/modern/class/ReactComponent.js: /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/core/ReactUpdateQueue.js: /Users/roger/Documents/AwesomeProject/node_modules/react-tools/src/core/ReactUpdates.js: undefined is not a function 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
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Jest Test Fail in React Native - Stack Overflow
The error I now see when executing the tests is: > trytest@0.0.1 test /home/xxxxx/MyAwesomeApp > jest FAIL __tests__/myfirst.test.js * Test ...
Read more >Testing React Native Apps - Jest
The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended...
Read more >Mocking RN modules | React Made Native Easy
i have introduced a native module called 'react-native-gps-state' in my personal project,but after running tests suits i'm getting error of "Invarient Voilation ...
Read more >Unit Testing in React: Full Guide on Jest and Enzyme Testing
Discover how to start and proceed with the testing of React components with Enzyme and Jest if you do not have enough experience...
Read more >Testing React Native apps with Jest | by Emily Xiong - Nx Blog
Jest encountered an unexpected tokenJest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard ...
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
I think we need a section in the docs about how to test your React Native components
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.