1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00
denoland-deno/js/fetch_test.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-08-30 13:49:24 -04:00
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
2018-09-05 02:29:02 -04:00
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
2018-08-30 13:49:24 -04:00
import * as deno from "deno";
testPerm({ net: true }, async function fetchJsonSuccess() {
const response = await fetch("http://localhost:4545/package.json");
const json = await response.json();
assertEqual(json.name, "deno");
});
2018-09-05 02:29:02 -04:00
test(async function fetchPerm() {
let err;
try {
await fetch("http://localhost:4545/package.json");
} catch (err_) {
err = err_;
}
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
assertEqual(err.name, "PermissionDenied");
2018-09-05 02:29:02 -04:00
});
2018-09-12 15:16:42 -04:00
testPerm({ net: true }, async function fetchHeaders() {
const response = await fetch("http://localhost:4545/package.json");
const headers = response.headers;
assertEqual(headers.get("Content-Type"), "application/json");
assert(headers.get("Server").startsWith("SimpleHTTP"));
});
test(async function headersAppend() {
let err;
try {
const headers = new Headers([["foo", "bar", "baz"]]);
} catch (e) {
err = e;
}
assert(err instanceof TypeError);
});
2018-09-14 13:56:37 -04:00
testPerm({ net: true }, async function fetchBlob() {
const response = await fetch("http://localhost:4545/package.json");
const headers = response.headers;
const blob = await response.blob();
assertEqual(blob.type, headers.get("Content-Type"));
assertEqual(blob.size, Number(headers.get("Content-Length")));
});