forked from jhen0409/rn-host-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (30 loc) · 1.09 KB
/
test.js
File metadata and controls
36 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
var assert = require('assert')
var sinon = require('sinon')
var getHost = require('./index')
var host = '10.0.3.2'
// window is undefined
assert.equal(getHost('localhost'), 'localhost')
assert.equal(getHost('127.0.0.1'), '127.0.0.1')
assert.equal(getHost('192.168.1.111'), '192.168.1.111')
console.warn = sinon.spy(console.warn)
// Expected `window.require` on React Native
global.window = {
__DEV__: true,
require: function(moduleName) {
// https://github.com/facebook/react-native/blob/5403946f098cc72c3d33ea5cee263fb3dd03891d/packager/src/Resolver/polyfills/require.js#L97
console.warn(
'Requiring module \'' + moduleName + '\' by name is only supported for ' +
'debugging purposes and will BREAK IN PRODUCTION!'
);
if (moduleName !== 'NativeModules') return undefined
return {
PlatformConstants: { ServerHost: host + ':8081' },
}
},
}
global.__fbBatchedBridge = {}
assert.equal(getHost('localhost'), host)
assert.equal(getHost('127.0.0.1'), host)
assert.equal(getHost('192.168.1.111'), '192.168.1.111')
assert.equal(console.warn.called, false)