/
arguments.js
62 lines (49 loc) 路 1.43 KB
/
arguments.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import test from 'ava';
import got from '../';
import {createServer} from './_server';
let s;
test.before('setup', async () => {
s = await createServer();
s.on('/', (req, res) => {
res.statusCode = 404;
res.end();
});
s.on('/test', (req, res) => {
res.end(req.url);
});
s.on('/?test=wow', (req, res) => {
res.end(req.url);
});
await s.listen(s.port);
});
test('url is required', async t => {
try {
await got();
t.fail('Exception was not thrown');
} catch (err) {
t.regexTest(/Parameter `url` must be a string or object, not undefined/, err.message);
}
});
test('options are optional', async t => {
t.is((await got(`${s.url}/test`)).body, '/test');
});
test('accepts url.parse object as first argument', async t => {
t.is((await got({hostname: s.host, port: s.port, path: '/test'})).body, '/test');
});
test('overrides querystring from opts', async t => {
t.is((await got(`${s.url}/?test=doge`, {query: {test: 'wow'}})).body, '/?test=wow');
});
test('should throw with auth in url', async t => {
try {
await got(`https://test:45d3ps453@account.myservice.com/api/token`);
t.fail('Exception was not thrown');
} catch (err) {
t.regexTest(/Basic authentication must be done with auth option/, err.message);
}
});
test('accepts url.parse object as first argument', async t => {
t.is((await got({hostname: s.host, port: s.port, path: '/test'})).body, '/test');
});
test.after('cleanup', async () => {
await s.close();
});