-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
35 lines (30 loc) · 794 Bytes
/
test.js
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
const xhrMock = require('xhr-mock');
const test = require('ava');
const validator = require('validator');
const {ipv4, ipv6} = require('./index');
const { default: mock,proxy } = xhrMock;
test('isipv4 server', async t => {
const ip = await ipv4();
t.true(validator.isIP(ip));
});
test('isipv6 server', async t => {
const ip = await ipv6();
t.true(validator.isIP(ip));
});
test('isipv4 browser', async t => {
mock.setup()
mock.use(proxy)
const ip = await ipv4();
t.true(validator.isIP(ip));
});
test('isipv6 browser', async t => {
mock.setup();
mock.use(proxy);
const ip = await ipv6();
t.true(validator.isIP(ip));
});
test('Custom IP api', async t => {
const body = await ipv6("https://postman-echo.com/ip");
const { ip } = JSON.parse(body);
t.true(validator.isIP(ip));
});