-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_test.ts
40 lines (37 loc) · 1.11 KB
/
fetch_test.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
import {
assertEqual,
runTests,
setFilter,
test
} from "https://deno.land/x/std@v0.2.8/testing/mod.ts";
import { fetch } from "./fetch.ts";
import { copy, open } from "deno";
import { ReadableStreamDenoReader } from "./util.ts";
import { readString } from "https://denopkg.com/keroxp/deno-request/strings.ts";
test(async function testGet() {
const res = await fetch("http://httpbin.org/get?deno=land", {
method: "GET"
});
console.log(await res.text());
const js = await res.json();
assertEqual(js["args"]["deno"], "land");
});
test(async function testPost() {
const res = await fetch("http://httpbin.org/post", {
method: "POST",
body: new URLSearchParams({
deno: "land"
})
});
console.log(await res.text());
const js = await res.json();
assertEqual(js["form"]["deno"], "land");
});
test(async function testGetAndFile() {
const f = await open("out.json", "w+");
const resp = await fetch("http://httpbin.org/get?deno=land");
const src = new ReadableStreamDenoReader(resp.body);
await copy(f, src).catch(e => f.close());
assertEqual("closed", resp.body.state);
});
runTests();