-
Notifications
You must be signed in to change notification settings - Fork 574
/
content_type_test.ts
43 lines (39 loc) · 1.44 KB
/
content_type_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
41
42
43
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { contentType } from "./content_type.ts";
import { assertEquals } from "../testing/asserts.ts";
Deno.test({
name: "media_types - contentType()",
fn() {
const fixtures = [
[".json", "application/json; charset=UTF-8"],
["text/html", "text/html; charset=UTF-8"],
["txt", "text/plain; charset=UTF-8"],
["text/plain; charset=ISO-8859-1", "text/plain; charset=ISO-8859-1"],
["foo", undefined],
["file.json", undefined],
["application/foo", "application/foo"],
] as const;
for (const [fixture, expected] of fixtures) {
assertEquals(contentType(fixture), expected);
}
},
});
Deno.test({
name: "media_types - contentType()",
fn() {
let _str: string;
// For well-known content types, the return type is a string.
// string is assignable to string
_str = contentType(".json");
_str = contentType("text/html");
_str = contentType("txt");
// @ts-expect-error: string | undefined is not assignable to string
_str = contentType("text/plain; charset=ISO-8859-1");
// @ts-expect-error: string | undefined is not assignable to string
_str = contentType("foo");
// @ts-expect-error: string | undefined is not assignable to string
_str = contentType("file.json");
// @ts-expect-error: string | undefined is not assignable to string
_str = contentType("application/foo");
},
});