forked from sindresorhus/ky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.ts
62 lines (52 loc) · 1.25 KB
/
methods.ts
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 ky from '../source/index.js';
import {createHttpTestServer} from './helpers/create-http-test-server.js';
test('common method is normalized', async t => {
const server = await createHttpTestServer();
server.all('/', (_request, response) => {
response.end();
});
await t.notThrowsAsync(
ky(server.url, {
method: 'get',
hooks: {
beforeRequest: [
(_input, options) => {
t.is(options.method, 'GET');
},
],
},
}),
);
await server.close();
});
test.failing('custom method remains identical', async t => {
const server = await createHttpTestServer();
server.all('/', (_request, response) => {
response.end();
});
t.plan(1);
await t.notThrowsAsync(
// TODO: Is it correct for this to throw 400 status code?
ky(server.url, {
method: 'report',
hooks: {
beforeRequest: [
(_input, options) => {
t.is(options.method, 'report');
},
],
},
}),
);
await server.close();
});
test('shortcut headers have correct accept headers set', async t => {
const server = await createHttpTestServer();
server.all('/', (request, response) => {
t.is(request.headers.accept, 'text/*');
response.end('whatever');
});
await ky.get(server.url).text();
await server.close();
});