deno.land / x / ky@v0.31.3 / test / fetch.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
63
64
65
66
import test from 'ava';import ky from '../source/index.js';
test.serial('relative URLs are passed to fetch unresolved', async t => { const originalFetch = globalThis.fetch; globalThis.fetch = async input => { if (typeof input !== 'object') { throw new TypeError('Expect to have an object request'); }
t.true(input.url.startsWith('/')); return new Response(input.url); };
t.is(await ky('/unicorn').text(), '/unicorn'); t.is(await ky('/unicorn', {searchParams: {foo: 'bar'}}).text(), '/unicorn?foo=bar'); t.is(await ky('/unicorn#hash', {searchParams: 'foo'}).text(), '/unicorn?foo#hash'); t.is(await ky('/unicorn?old', {searchParams: 'new'}).text(), '/unicorn?new'); t.is(await ky('/unicorn?old#hash', {searchParams: 'new'}).text(), '/unicorn?new#hash'); t.is(await ky('unicorn', {prefixUrl: '/api/'}).text(), '/api/unicorn'); globalThis.fetch = originalFetch;});
test('fetch option takes a custom fetch function', async t => { t.plan(6);
const customFetch: typeof fetch = async input => { if (!(input instanceof Request)) { throw new TypeError('Expected to have input as request'); }
return new Response(input.url); };
t.is(await ky('/unicorn', {fetch: customFetch}).text(), '/unicorn'); t.is( await ky('/unicorn', { fetch: customFetch, searchParams: {foo: 'bar'}, }).text(), '/unicorn?foo=bar', ); t.is( await ky('/unicorn#hash', { fetch: customFetch, searchParams: 'foo', }).text(), '/unicorn?foo#hash', ); t.is( await ky('/unicorn?old', { fetch: customFetch, searchParams: 'new', }).text(), '/unicorn?new', ); t.is( await ky('/unicorn?old#hash', { fetch: customFetch, searchParams: 'new', }).text(), '/unicorn?new#hash', ); t.is(await ky('unicorn', {fetch: customFetch, prefixUrl: '/api/'}).text(), '/api/unicorn');});
ky

Version Info

Tagged at
a year ago