In test ONLY: @react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null.
See original GitHub issueBug
The error above happens when running yarn test
. The app have been updated with the latest release of 2.2.2. But the tricky is that my app works fine when launching with react-native run-android
. I can load the Event
component without error.
Environment info
React native info output:
PS C:\d\code\js\emps_fe> react-native link react-native-device-info
info iOS module "react-native-device-info" is already linked
info Android module "react-native-device-info" is already linked
PS C:\d\code\js\emps_fe> yarn test
yarn run v1.15.2
$ jest
FAIL __tests__/App-test.js
● Test suite failed to run
@react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:
• Run `react-native link react-native-device-info` in the project root.
• Rebuild and re-run the app.
• If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-device-info
2 | import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native';
3 | import moment from 'moment';
> 4 | import DeviceInfo from 'react-native-device-info';
| ^
5 | import helper from "../../lib/helper";
6 | import GLOBAL from "../../lib/global";
7 |
at Object.<anonymous> (node_modules/react-native-device-info/deviceinfo.js:19:11)
at Object.<anonymous> (src/components/event/Event.js:4:1)
FAIL __tests__/Event.test.js
● Test suite failed to run
@react-native-community/react-native-device-info: NativeModule.RNDeviceInfo is null. To fix this issue try these steps:
• Run `react-native link react-native-device-info` in the project root.
• Rebuild and re-run the app.
• If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-device-info
2 | import { SectionList, View, Image, StyleSheet, Text, TouchableOpacity, Platform, TouchableHighlight, AppRegistry } from 'react-native';
3 | import moment from 'moment';
> 4 | import DeviceInfo from 'react-native-device-info';
| ^
5 | import helper from "../../lib/helper";
6 | import GLOBAL from "../../lib/global";
7 |
at Object.<anonymous> (node_modules/react-native-device-info/deviceinfo.js:19:11)
at Object.<anonymous> (src/components/event/Event.js:4:1)
Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 6.493s
Ran all test suites.
error Command failed with exit code 1.
Library version: x.x.x Here is the package.json: “dependencies”: { “moment”: “^2.24.0”, “react”: “16.8.3”, “react-native”: “0.59.9”, “react-native-cli”: “^2.0.1”, “react-native-confirmation-code-field”: “^3.6.0”, “react-native-device-info”: “^2.2.2”, “react-native-elements”: “^1.1.0”, “react-native-gesture-handler”: “^1.3.0”, “react-native-gifted-chat”: “^0.9.11”, “react-native-keychain”: “^3.1.3”, “react-native-linear-gradient”: “^2.5.4”, “react-native-modal”: “^11.0.2”, “react-native-modal-datetime-picker”: “^7.4.2”, “react-native-paper”: “^2.16.0”, “react-native-segmented-control-tab”: “^3.4.0”, “react-native-vector-icons”: “^6.5.0”, “react-navigation”: “^3.11.0”, “socket.io-client”: “2.1.1” }, “devDependencies”: { “@babel/core”: “^7.4.5”, “@babel/runtime”: “^7.4.5”, “babel-jest”: “^24.8.0”, “jest”: “^24.8.0”, “metro-react-native-babel-preset”: “^0.54.1”, “react-test-renderer”: “16.8.3” },
Steps To Reproduce
…
Describe what you expected to happen:
Reproducible sample code
Here is the test code:
import ‘react-native’; import React from ‘react’; import App from ‘…/App’;
// Note: test renderer must be required after react-native. import renderer from ‘react-test-renderer’;
it(‘renders correctly’, () => { const tree = renderer.create(<Event />).toJSON(); expect(tree).toMatchSnapshot(); });
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:10
Top GitHub Comments
@tmaly1980 there really should be! I look forward to your contributed mock file pull request and will merge it happily
● Test suite failed to run