Skip to content

Commit

Permalink
fix: Add instructions for integrating with Jest unit tests (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oakes authored May 24, 2019
1 parent 3d1b241 commit 3bfdd45
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,30 @@ const YourComplement = () => {
};
```
## Known issues with the iOS simulator
## Troubleshooting
### Errors while running Jest tests
If you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the `jest.setup.js` file in project root:
```js
setupFiles: ['<rootDir>/jest.setup.js']
```
You should then add the following to your Jest setup file to mock the NetInfo Native Module:
```js
import { NativeModules } from 'react-native';

NativeModules.RNCNetInfo = {
getCurrentConnectivity: jest.fn(),
isConnectionMetered: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn()
};
```
### Issues with the iOS simulator
There is a [known](http://openradar.appspot.com/14585459) [issue](http://www.openradar.appspot.com/29913522) with the iOS Simulator which causes it to not receive network change notifications correctly when the host machine disconnects and then connects to Wifi. If you are having issues with iOS then please test on an actual device before reporting any bugs.
Expand Down
2 changes: 2 additions & 0 deletions src/internal/nativeInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ if (!RNCNetInfo) {
• Run \`react-native link @react-native-community/netinfo\` 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.
• Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.
* If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo`);
}
Expand Down

0 comments on commit 3bfdd45

Please sign in to comment.