-
Notifications
You must be signed in to change notification settings - Fork 20
/
elementProto.spec.ts
77 lines (64 loc) · 2.23 KB
/
elementProto.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
import { useResetDOM, useDOMElement, useIVI, useTest, useHTML, useComputedValue } from "ivi-jest";
import { ElementProtoDescriptor } from "../element_proto";
import { Op } from "ivi";
useResetDOM();
const root = useDOMElement();
const ivi = useIVI();
const h = useHTML();
const t = useTest();
const _ = void 0;
const r = (op: Op) => t.render(op, root()).domNode!;
describe("elementProto", () => {
describe("factory", () => {
const proto = useComputedValue(() => h.div());
const factory = useComputedValue(() => ivi.elementProto(proto));
test("flags", () => {
const op = factory();
expect(op.t.f & ~ivi.NodeFlags.ElementProto).toBe(proto.t.f);
});
test("descriptor", () => {
const op = factory();
expect((op.t.d as ElementProtoDescriptor).p).toBe(proto);
});
test("default className is undefined", () => {
const op = factory();
expect(op.n).toBeUndefined();
});
test("override className", () => {
const op = factory("abc");
expect(op.n).toBe("abc");
});
test("throw an error when element proto has children", () => {
expect(() => ivi.elementProto(h.div(_, _, h.div()))).toThrowError("children");
});
});
describe("mount", () => {
test("basic element", () => {
const factory = ivi.elementProto(h.div());
expect(r(factory())).toMatchSnapshot();
});
test("predefined className", () => {
const factory = ivi.elementProto(h.div("abc"));
expect(r(factory())).toMatchSnapshot();
});
test("override className", () => {
const factory = ivi.elementProto(h.div("abc"));
expect(r(factory("def"))).toMatchSnapshot();
});
test("predefined attribute", () => {
const factory = ivi.elementProto(h.div(_, { height: "10px" }));
expect(r(factory())).toMatchSnapshot();
});
test("override attribute", () => {
const factory = ivi.elementProto(h.div(_, { height: "10px" }));
expect(r(factory(_, { height: "20px" }))).toMatchSnapshot();
});
});
describe("update", () => {
test("override attribute", () => {
const factory = ivi.elementProto(h.div(_, { height: "10px" }));
r(factory());
expect(r(factory(_, { height: "20px" }))).toMatchSnapshot();
});
});
});