deno.land / std@0.224.0 / media_types / content_type_test.ts

content_type_test.ts
View Documentation
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
44
45
46
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { contentType } from "./content_type.ts";import { assertEquals } from "../assert/mod.ts";
Deno.test({ name: "contentType()", fn() { const fixtures = [ [" ; charset=UTF-8", undefined], [".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"], ["text/plan; charset", undefined], ["foo", undefined], ["file.json", undefined], ["application/foo", "application/foo"], ] as const; for (const [fixture, expected] of fixtures) { assertEquals(contentType(fixture), expected); } },});
Deno.test({ name: "contentType() implies types", 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"); },});
std

Version Info

Tagged at
6 months ago