Skip to content

Commit

Permalink
feat: checking internet if pingServerUrl changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommezz committed Feb 2, 2019
1 parent 121cb5d commit a7c7c4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-offline",
"version": "4.1.4",
"version": "4.2.0",
"description": "Handy toolbelt to deal with offline mode in React Native applications. Cross-platform, provides a smooth redux integration.",
"main": "./src/index.js",
"author": "Raul Gomez Acuña <raulgdeveloper@gmail.com> (https://github.com/rgommezz)",
Expand Down Expand Up @@ -80,6 +80,9 @@
"setupTestFrameworkScriptFile": "<rootDir>/test/setupTestEnv.js",
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"modulePathIgnorePatterns": [
"<rootDir>/example/"
]
}
}
7 changes: 5 additions & 2 deletions src/components/NetworkConnectivity.js
Expand Up @@ -91,9 +91,12 @@ class NetworkConnectivity extends React.PureComponent<Props, State> {
}
}

componentDidUpdate(_: *, prevState: State) {
componentDidUpdate(prevProps: Props, prevState: State) {
const { pingServerUrl, onConnectivityChange } = this.props;
const { isConnected } = this.state;
const { onConnectivityChange } = this.props;
if (prevProps.pingServerUrl !== pingServerUrl) {
this.checkInternet();
}
if (prevState.isConnected !== isConnected) {
onConnectivityChange(isConnected);
}
Expand Down
10 changes: 10 additions & 0 deletions test/NetworkConnectivity.test.js
Expand Up @@ -336,6 +336,16 @@ describe('NetworkConnectivity', () => {
});
});

describe('pingUrlChange', () => {
it('calls checkInternet if pingServerUrl changes', () => {
const wrapper = shallow(getElement());
wrapper.instance().checkInternet = mockCheckInternet;
expect(mockCheckInternet).not.toHaveBeenCalled();
wrapper.setProps({ pingServerUrl: 'https://newServerToPing.com' });
expect(mockCheckInternet).toHaveBeenCalled();
});
})

describe('props validation', () => {
it('throws if prop pingTimeout is not a number', () => {
expect(() =>
Expand Down

0 comments on commit a7c7c4c

Please sign in to comment.