Skip to content

Commit

Permalink
Add lint and unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
superguineapig committed Dec 11, 2018
1 parent 6fc5164 commit 00bef86
Show file tree
Hide file tree
Showing 6 changed files with 6,923 additions and 75 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
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"
}
}
35 changes: 35 additions & 0 deletions __mocks__/react-native-ntp-client.js
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;
Loading

0 comments on commit 00bef86

Please sign in to comment.