-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_test.ts
73 lines (61 loc) · 2.11 KB
/
html_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
import { assertStrictEq, prepareTest } from "../test.mod.ts";
import { helloWorld, peopleList } from "./CONSTANTS.ts";
import { html } from "./mod.ts";
async function willRender() {
const d = await html`${helloWorld}`;
assertStrictEq(
d,
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1></body></html>`
);
}
async function willRenderWithSyncTasks() {
const syncTask = () => helloWorld;
const syncLiteral = "John Doe";
const d = await html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`;
assertStrictEq(
d,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
);
}
async function willRenderWithAsyncTasks() {
const asyncTask = async () => helloWorld;
const asyncLiteral = Promise.resolve("John Doe");
const d = await html`<section>${asyncTask}<h2>${asyncLiteral}</h2></section>`;
assertStrictEq(
d,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
);
}
async function willRenderWithSyncAndAsyncTasks() {
const asyncTask = async () => helloWorld;
const syncLiteral = await "John Doe";
const d = await html`<section>${asyncTask}<h2>${syncLiteral}</h2></section>`;
assertStrictEq(
d,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
);
}
async function willRenderAListofSyncTasks() {
const d = await html`${helloWorld}<ul>${peopleList.map(
n => `<li>${n}</li>`
)}</ul>`;
assertStrictEq(
d,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul></body></html>`
);
}
prepareTest(
[
willRender,
willRenderAListofSyncTasks,
willRenderWithAsyncTasks,
willRenderWithSyncAndAsyncTasks,
willRenderWithSyncTasks
],
"lit_ntml",
"html"
);