-
Notifications
You must be signed in to change notification settings - Fork 16
/
basic-schema.test.ts
64 lines (60 loc) · 1.41 KB
/
basic-schema.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
import { validateMMLDocument } from "../src";
test("basic cubes", () => {
const validationErrors = validateMMLDocument(`
<m-cube color="red">
<m-cube color="green">
<m-cube color="blue"></m-cube>
</m-cube>
</m-cube>
`);
expect(validationErrors).toBeNull();
});
test("basic cubes document inside html tag", () => {
const validationErrors = validateMMLDocument(`
<html>
<head></head>
<body>
<m-cube color="red">
<m-cube color="green">
<m-cube color="blue"></m-cube>
</m-cube>
</m-cube>
</body>
</html>
`);
expect(validationErrors).toBeNull();
});
test("invalid tag throws error", () => {
const validationErrors: Array<Error> | null = validateMMLDocument(`
<html>
<head></head>
<body>
<m-notathing color="red">
<m-cube color="green">
<m-cube color="blue"></m-cube>
</m-cube>
</m-notathing>
</body>
</html>
`)!;
expect(validationErrors[0].message).toContain(
"Element 'm-notathing': This element is not expected.",
);
});
test("invalid attribute throws error", () => {
const validationErrors: Array<Error> | null = validateMMLDocument(`
<html>
<head></head>
<body>
<m-cube notathing="foo">
<m-cube color="green">
<m-cube color="blue"></m-cube>
</m-cube>
</m-cube>
</body>
</html>
`)!;
expect(validationErrors[0].message).toContain(
"attribute 'notathing': The attribute 'notathing' is not allowed.",
);
});