summaryrefslogtreecommitdiff
path: root/cli/js/headers_test.ts
diff options
context:
space:
mode:
authorRory Malcolm <rory.malcolm@digital.cabinet-office.gov.uk>2019-10-28 16:23:39 +0000
committerRy Dahl <ry@tinyclouds.org>2019-10-28 12:23:39 -0400
commit967c236fa5fb1e87e1b5ee788fe77d3a07361da1 (patch)
tree839f348ec0e9a80f41a381dd60b0b61f5cfb33a5 /cli/js/headers_test.ts
parentefd7e78af3fc086dfdec51738905665d38d08eb4 (diff)
Add CustomInspect for Headers (#3130)
Worth noting due to implementation of the Headers class the contents of headersMap have lowercase keys, although this matches the specification as header keys are case agnostic it does seem to not match behaviour of other implementations in other languages I have seen, would require some rewriting of Headers.ts
Diffstat (limited to 'cli/js/headers_test.ts')
-rw-r--r--cli/js/headers_test.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/cli/js/headers_test.ts b/cli/js/headers_test.ts
index f08283c51..a01abb6a6 100644
--- a/cli/js/headers_test.ts
+++ b/cli/js/headers_test.ts
@@ -1,5 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEquals } from "./test_util.ts";
+const {
+ stringifyArgs
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+} = Deno as any;
// Logic heavily copied from web-platform-tests, make
// sure pass mostly header basic test
@@ -329,3 +333,25 @@ test(function toStringShouldBeWebCompatibility(): void {
const headers = new Headers();
assertEquals(headers.toString(), "[object Headers]");
});
+
+function stringify(...args: unknown[]): string {
+ return stringifyArgs(args).replace(/\n$/, "");
+}
+
+test(function customInspectReturnsCorrectHeadersFormat(): void {
+ const blankHeaders = new Headers();
+ assertEquals(stringify(blankHeaders), "Headers {}");
+ const singleHeader = new Headers([["Content-Type", "application/json"]]);
+ assertEquals(
+ stringify(singleHeader),
+ "Headers { content-type: application/json }"
+ );
+ const multiParamHeader = new Headers([
+ ["Content-Type", "application/json"],
+ ["Content-Length", "1337"]
+ ]);
+ assertEquals(
+ stringify(multiParamHeader),
+ "Headers { content-type: application/json, content-length: 1337 }"
+ );
+});