/
index.spec.ts
53 lines (45 loc) · 1.31 KB
/
index.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
import {
parseDocument,
parseDOM,
createDomStream,
DomHandler,
DefaultHandler,
} from ".";
import { Element } from "domhandler";
// Add an `attributes` prop to the Element for now, to make it possible for Jest to render DOM nodes.
Object.defineProperty(Element.prototype, "attributes", {
get() {
return Object.keys(this.attribs).map((name) => ({
name,
value: this.attribs[name],
}));
},
configurable: true,
enumerable: false,
});
describe("Index", () => {
test("parseDocument", () => {
const dom = parseDocument("<a foo><b><c><?foo>Yay!");
expect(dom).toMatchSnapshot();
});
test("parseDOM", () => {
const dom = parseDOM("<a foo><b><c><?foo>Yay!");
expect(dom).toMatchSnapshot();
});
test("createDomStream", (done) => {
const domStream = createDomStream((err, dom) => {
expect(err).toBeNull();
expect(dom).toMatchSnapshot();
done();
});
for (const c of "&This is text<!-- and comments --><tags>") {
domStream.write(c);
}
domStream.end();
});
describe("API", () => {
it("should export the appropriate APIs", () => {
expect(DomHandler).toEqual(DefaultHandler);
});
});
});