-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fc5164
commit 00bef86
Showing
6 changed files
with
6,923 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"globals": { | ||
"clearInterval": false, | ||
"console": false, | ||
"module": true, | ||
"require": false, | ||
"setInterval": false | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 5 | ||
}, | ||
"rules": { | ||
"no-console": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// __mocks__/react-native-ntp-client.js | ||
'use strict'; | ||
|
||
const client = jest.genMockFromModule('react-native-ntp-client'); | ||
|
||
// a fake NTP server domain that triggers the error callback in 'getNetworkTime' | ||
const MOCK_FAILING_SERVER = 'FAIL.FAIL.FAIL'; | ||
|
||
// internal value to mock an NTP server's delta time in ms | ||
var __offset_ms = 0; | ||
|
||
// custom method to allow tests to set a server delta time | ||
// can be +/- (values in milliseconds) | ||
function __setOffsetMs(ms) { | ||
__offset_ms = ms; | ||
} | ||
|
||
// custom getNetworkTime that simply calls callback | ||
function getNetworkTime(s, p, cb) { | ||
if (cb) { | ||
if (s === MOCK_FAILING_SERVER) { | ||
cb(new Error('Mock Error'), null); | ||
} else { | ||
cb(null, new Date( Date.now() + __offset_ms )); | ||
} | ||
} | ||
} | ||
|
||
/**** mocked API ****/ | ||
client.MOCK_FAILING_SERVER = MOCK_FAILING_SERVER; | ||
client.__setOffsetMs = __setOffsetMs; | ||
// overrides | ||
client.getNetworkTime = getNetworkTime; | ||
|
||
module.exports = client; |
Oops, something went wrong.