generated from kawarimidoll/deno-dev-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
84 lines (79 loc) · 1.87 KB
/
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
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
import {
assertEquals,
assertThrows,
} from "https://deno.land/std@0.102.0/testing/asserts.ts";
import { tag } from "./mod.ts";
Deno.test("render tag", () => {
assertEquals(
tag("div", { id: "foo", class: "bar" }, "Hello world!"),
`<div id="foo" class="bar">Hello world!</div>`,
);
assertEquals(
tag("my-tag", { class: "bar" }, "My own tag!"),
`<my-tag class="bar">My own tag!</my-tag>`,
);
});
Deno.test("render void tag", () => {
assertEquals(
tag("meta", { charset: "utf-8" }),
`<meta charset="utf-8">`,
);
assertEquals(
tag("input", {
type: "text",
name: "name",
placeholder: "input your name",
}),
`<input type="text" name="name" placeholder="input your name">`,
);
});
Deno.test("render tag without attributes", () => {
assertEquals(
tag("div", "No attributes!"),
`<div>No attributes!</div>`,
);
assertEquals(
tag("br"),
`<br>`,
);
});
Deno.test("render nested tag", () => {
assertEquals(
tag(
"a",
{ href: "https://deno.land" },
tag("img", { src: "https://deno.land/logo.svg" }),
),
`<a href="https://deno.land"><img src="https://deno.land/logo.svg"></a>`,
);
assertEquals(
tag(
"ul",
{ class: "nav" },
tag("li", "first element"),
tag("li", "second element"),
),
`<ul class="nav"><li>first element</li><li>second element</li></ul>`,
);
assertEquals(
tag(
"div",
{ class: "container" },
tag(
"article",
{ class: "post" },
tag("p", "awesome text"),
),
),
`<div class="container"><article class="post"><p>awesome text</p></article></div>`,
);
});
Deno.test("throw error when tag has whitespace characters", () => {
assertThrows(
() => {
tag("separate tag", { id: "foo" }, "Hello world!");
},
Error,
"tagName has whitespace characters.",
);
});