/
vnode_element.spec.ts
105 lines (85 loc) · 2.7 KB
/
vnode_element.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
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
97
98
99
100
101
102
103
104
105
import { EventHandler, VNodeFlags, VNode, t, UNSAFE_HTML, getComponent } from "ivi";
import * as h from "ivi-html";
test(`element flags`, () => {
const v = h.div();
expect(v._f & VNodeFlags.Element).toBeTruthy();
});
test(`tagName`, () => {
const v = h.div();
expect(v._t).toBe("div");
});
test(`default className should be undefined`, () => {
const v = h.div();
expect(v._cs).toBe(undefined);
});
test(`className=undefined`, () => {
const v = h.div(undefined);
expect(v._cs).toBe(undefined);
});
test(`className="cls"`, () => {
const v = h.div("cls");
expect(v._cs).toBe("cls");
});
test(`explicit key`, () => {
const v = h.div().k("k");
expect(v._f & VNodeFlags.Key).toBeTruthy();
expect(v._k).toBe("k");
});
test(`style`, () => {
const s = { top: "10px" };
const v = h.div("", void 0, s);
expect(v._s).toBe(s);
});
test(`events`, () => {
const s: EventHandler[] = [];
const v = h.div().e(s);
expect(v._e).toBe(s);
});
test(`attributes`, () => {
const s = {};
const v = h.div("", s);
expect(v._p).toBe(s);
});
test(`children`, () => {
const v = h.div().c("abc");
expect((v._c as VNode)._p as string).toBe("abc");
});
test(`assigning text content to void elements should raise an exception`, () => {
expect(() => h.input().t("abc")).toThrow(Error);
});
test(`assigning text content to element with unsafeHTML should raise an exception`, () => {
expect(() => h.div("", { unsafeHTML: UNSAFE_HTML("<span></span>") }).t("abc")).toThrow(Error);
});
test(`overwriting text content should raise an exception`, () => {
const v = h.div().t("abc");
expect(() => v.t("123")).toThrow(Error);
});
test(`overwriting children with text content should raise an exception`, () => {
const v = h.div().c("abc");
expect(() => v.t("123")).toThrow(Error);
});
test(`overwriting children should raise an exception`, () => {
const v = h.div().c("abc");
expect(() => v.c("123")).toThrow(Error);
});
test(`overwriting text content with children should raise an exception`, () => {
const v = h.div().t("abc");
expect(() => v.c("123")).toThrow(Error);
});
test(`assigning children to void elements should raise an exception`, () => {
expect(() => h.input().c("abc")).toThrow(Error);
});
test(`assigning children to element with unsafeHTML should raise an exception`, () => {
expect(() => h.div("", { unsafeHTML: UNSAFE_HTML("<span></span>") }).c("abc")).toThrow(Error);
});
test(`children with duplicate keys should raise an exception`, () => {
expect(() => (
h.div().c(
t("").k("a"),
t("").k("a"),
)
)).toThrow(Error);
});
test(`getComponent should raise an exception when it is invoked on a non-component node`, () => {
expect(() => getComponent(h.div())).toThrowError();
});