Skip to content

Commit

Permalink
Fix Jest mocks for NetInfo module.
Browse files Browse the repository at this point in the history
Summary:
Jest mock for `NetInfo.getConnectionInfo()` is missing. Tests are fail with error message:
```
TypeError: _reactNative.NetInfo.getConnectionInfo is not a function
```
And cleaned code in this files for unified code styles.

Run test with usage of `NetInfo.getConnectionInfo()`

[GENERAL] [BUGFIX] [jest/setup.js] - Fix Jest mocks for NetInfo module
Closes facebook#16722

Differential Revision: D6298133

Pulled By: hramos

fbshipit-source-id: 589cf6fed93965e7a09823015f2793f5c68a9c3b
  • Loading branch information
timwangdev authored and facebook-github-bot committed Nov 10, 2017
1 parent 58c3bc4 commit 7fb3a92
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const mockNativeModules = {
},
ImageLoader: {
getSize: jest.fn(
(url) => new Promise(() => ({width: 320, height: 240}))
(url) => Promise.resolve({width: 320, height: 240})
),
prefetchImage: jest.fn(),
},
Expand All @@ -179,11 +179,11 @@ const mockNativeModules = {
Linking: {
openURL: jest.fn(),
canOpenURL: jest.fn(
() => new Promise((resolve) => resolve(true))
() => Promise.resolve(true)
),
addEventListener: jest.fn(),
getInitialURL: jest.fn(
() => new Promise((resolve) => resolve())
() => Promise.resolve()
),
removeEventListener: jest.fn(),
},
Expand All @@ -195,15 +195,23 @@ const mockNativeModules = {
ModalFullscreenViewManager: {},
NetInfo: {
fetch: jest.fn(
() => new Promise((resolve) => resolve())
() => Promise.resolve()
),
getConnectionInfo: jest.fn(
() => Promise.resolve()
),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
isConnected: {
fetch: jest.fn(
() => new Promise((resolve) => resolve())
() => Promise.resolve()
),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
},
isConnectionExpensive: jest.fn(
() => Promise.resolve()
),
},
Networking: {
sendRequest: jest.fn(),
Expand Down

0 comments on commit 7fb3a92

Please sign in to comment.