summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/body_test.ts2
-rw-r--r--cli/tests/unit/request_test.ts28
2 files changed, 23 insertions, 7 deletions
diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts
index 404ae305d..4839d4094 100644
--- a/cli/tests/unit/body_test.ts
+++ b/cli/tests/unit/body_test.ts
@@ -4,7 +4,7 @@ import { assert, assertEquals, unitTest } from "./test_util.ts";
// just a hack to get a body object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildBody(body: any, headers?: Headers): Body {
- const stub = new Request("", {
+ const stub = new Request("http://foo/", {
body: body,
headers,
});
diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts
index c8b8377d4..f1d5ef055 100644
--- a/cli/tests/unit/request_test.ts
+++ b/cli/tests/unit/request_test.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert, assertEquals, unitTest } from "./test_util.ts";
+import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
unitTest(function fromInit(): void {
- const req = new Request("https://example.com", {
+ const req = new Request("http://foo/", {
body: "ahoyhoy",
method: "POST",
headers: {
@@ -12,12 +12,12 @@ unitTest(function fromInit(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assertEquals("ahoyhoy", (req as any)._bodySource);
- assertEquals(req.url, "https://example.com");
+ assertEquals(req.url, "http://foo/");
assertEquals(req.headers.get("test-header"), "value");
});
unitTest(function fromRequest(): void {
- const r = new Request("https://example.com");
+ const r = new Request("http://foo/");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(r as any)._bodySource = "ahoyhoy";
r.headers.set("test-header", "value");
@@ -30,10 +30,26 @@ unitTest(function fromRequest(): void {
assertEquals(req.headers.get("test-header"), r.headers.get("test-header"));
});
+unitTest(function requestNonString(): void {
+ const nonString = {
+ toString() {
+ return "http://foo/";
+ },
+ };
+ // deno-lint-ignore ban-ts-comment
+ // @ts-expect-error
+ assertEquals(new Request(nonString).url, "http://foo/");
+});
+
+unitTest(function requestRelativeUrl(): void {
+ // TODO(nayeemrmn): Base from `--location` when implemented and set.
+ assertThrows(() => new Request("relative-url"), TypeError, "Invalid URL.");
+});
+
unitTest(async function cloneRequestBodyStream(): Promise<void> {
// hack to get a stream
- const stream = new Request("", { body: "a test body" }).body;
- const r1 = new Request("https://example.com", {
+ const stream = new Request("http://foo/", { body: "a test body" }).body;
+ const r1 = new Request("http://foo/", {
body: stream,
});