Skip to content

Commit a7c7c4c

Browse files
committed
feat: checking internet if pingServerUrl changes
1 parent 121cb5d commit a7c7c4c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-offline",
3-
"version": "4.1.4",
3+
"version": "4.2.0",
44
"description": "Handy toolbelt to deal with offline mode in React Native applications. Cross-platform, provides a smooth redux integration.",
55
"main": "./src/index.js",
66
"author": "Raul Gomez Acuña <raulgdeveloper@gmail.com> (https://github.com/rgommezz)",
@@ -80,6 +80,9 @@
8080
"setupTestFrameworkScriptFile": "<rootDir>/test/setupTestEnv.js",
8181
"transform": {
8282
"^.+\\.jsx?$": "babel-jest"
83-
}
83+
},
84+
"modulePathIgnorePatterns": [
85+
"<rootDir>/example/"
86+
]
8487
}
8588
}

src/components/NetworkConnectivity.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ class NetworkConnectivity extends React.PureComponent<Props, State> {
9191
}
9292
}
9393

94-
componentDidUpdate(_: *, prevState: State) {
94+
componentDidUpdate(prevProps: Props, prevState: State) {
95+
const { pingServerUrl, onConnectivityChange } = this.props;
9596
const { isConnected } = this.state;
96-
const { onConnectivityChange } = this.props;
97+
if (prevProps.pingServerUrl !== pingServerUrl) {
98+
this.checkInternet();
99+
}
97100
if (prevState.isConnected !== isConnected) {
98101
onConnectivityChange(isConnected);
99102
}

test/NetworkConnectivity.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,16 @@ describe('NetworkConnectivity', () => {
336336
});
337337
});
338338

339+
describe('pingUrlChange', () => {
340+
it('calls checkInternet if pingServerUrl changes', () => {
341+
const wrapper = shallow(getElement());
342+
wrapper.instance().checkInternet = mockCheckInternet;
343+
expect(mockCheckInternet).not.toHaveBeenCalled();
344+
wrapper.setProps({ pingServerUrl: 'https://newServerToPing.com' });
345+
expect(mockCheckInternet).toHaveBeenCalled();
346+
});
347+
})
348+
339349
describe('props validation', () => {
340350
it('throws if prop pingTimeout is not a number', () => {
341351
expect(() =>

0 commit comments

Comments
 (0)