deno.land / x / diplodocus@0.0.3 / utils_test.ts

utils_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { assertEquals, assertThrows } from "./deps.ts";import { aTag, genResponseArgs, getH1, toTitle } from "./utils.ts";
Deno.test("[aTag] throws error", () => { assertThrows( () => { aTag({ href: 1 }, "Posts"); }, Error, "href must be a string", );});
Deno.test("[aTag] internal link", () => { assertEquals( aTag({ href: "/about" }, "About"), `<a href="/about">About</a>`, ); assertEquals( aTag({ href: "posts" }, "Posts"), `<a href="/posts">Posts</a>`, ); assertEquals( aTag({ href: "#ex" }, "Examples"), `<a href="#ex">Examples</a>`, );});
Deno.test("[aTag] external link", () => { assertEquals( aTag({ href: "https://github.com" }, "GitHub"), `<a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="feather"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg></a>`, );});
Deno.test("[getH1] get h1 tag", () => { assertEquals( getH1("<body><h1>header 1 </h1><h2>header 2</h2></body>"), "header 1", ); assertEquals( getH1(`<body><h1><span id="h1">header</span> 1</h1><p>text</p></body>`), "header 1", );});
Deno.test("[getH1] blank", () => { assertEquals( getH1("<body><h2>header 2</h2></body>"), "", ); assertEquals( getH1(""), "", );});
Deno.test("[toTitle] turn into a title", () => { assertEquals( toTitle("this-is-title"), "This is title", ); assertEquals( toTitle("/path/to/the_file"), "Path to the file", );});
Deno.test("[getH1] get h1 tag", () => { assertEquals( getH1("<body><h1>header 1</h1><h2>header 2</h2><h1>3rd</h1></body>"), "header 1", ); assertEquals( getH1( `<body><h1><span id="h1">header</span> 1</h1><h1>header 2</h1></body>`, ), "header 1", );});
Deno.test("[genResponseArgs] generate response arguments", () => { assertEquals( genResponseArgs(404), [`404: Not Found`, { status: 404, statusText: "Not Found" }], ); assertEquals( genResponseArgs(302, { headers: { location: "https://github.com" } }), [`302: Moved Temporarily`, { headers: { location: "https://github.com" }, status: 302, statusText: "Moved Temporarily", }], );});
diplodocus
🦕 Deno Deploy Docs 📓
DocumentationDocumentation
GitHub Stars
21

Version Info

Tagged at
7 months ago