-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdoctype.spec.ts
56 lines (55 loc) · 1.62 KB
/
doctype.spec.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
import test from "ava";
import { Doctype } from "..";
import { HTMLRewriter, wait } from ".";
const doctypeInput =
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"></html>';
test("handles document doctype properties", async (t) => {
t.plan(4);
const res = await new HTMLRewriter()
.onDocument({
doctype(doctype) {
t.is(doctype.name, "html");
t.is(doctype.publicId, "-//W3C//DTD HTML 4.01//EN");
t.is(doctype.systemId, "http://www.w3.org/TR/html4/strict.dtd");
},
})
.transform(doctypeInput);
t.is(res, doctypeInput);
});
test("handles document doctype properties for empty doctype", async (t) => {
t.plan(3);
await new HTMLRewriter()
.onDocument({
doctype(doctype) {
t.is(doctype.name, null);
t.is(doctype.publicId, null);
t.is(doctype.systemId, null);
},
})
.transform("<!DOCTYPE>");
});
test("handles document doctype async handler", async (t) => {
const res = await new HTMLRewriter()
.onDocument({
async doctype(doctype) {
await wait(50);
t.is(doctype.name, "html");
},
})
.transform(doctypeInput);
t.is(res, doctypeInput);
});
test("handles document doctype class handler", async (t) => {
class Handler {
constructor(private content: string) {}
// noinspection JSUnusedGlobalSymbols
doctype(doctype: Doctype) {
t.is(doctype.name, "html");
t.is(this.content, "new");
}
}
const res = await new HTMLRewriter()
.onDocument(new Handler("new"))
.transform(doctypeInput);
t.is(res, doctypeInput);
});