-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-errors.js
100 lines (87 loc) · 2.8 KB
/
test-errors.js
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
import { test, expect } from 'vitest';
import { process } from './process.js';
test('Throws if namespace is unknown', async () => {
await expect(() => process(
`<div><x-unknown-namespace::button>Submit</x-unknown-namespace::button></div>`,
{ root: './test/templates', strict: true }
)).rejects.toThrow();
});
test('Throws when push tag missing name attribute', async () => {
await expect(() => process(
`<div><push></push></div>`,
{
root: './test/templates',
strict: true
}
)).rejects.toThrow();
});
test('Throws when push tag missing name attribute value', async () => {
await expect(() => process(
`<div><push name></push></div>`,
{ root: './test/templates', strict: true }
)).rejects.toThrow();
});
test('Throws when component is not found (strict mode enabled)', async () => {
await expect(() => process(
`<div><component src="not-found.html">Submit</component></div>`,
{
root: './test/templates/empty-root',
tag: 'component',
strict: true,
}
)).rejects.toThrow();
});
test('Throws when component is not found in namespace (strict mode enabled)', async () => {
await expect(() => process(
`<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>`,
{
root: './test/templates',
strict: true,
namespaces: [
{
name: 'empty-namespace',
root: './test/templates/empty-namespace',
}
]
}
)).rejects.toThrow();
});
test('Returns node as-is when namespace is unknown (strict mode disabled)', async () => {
const actual = `<div><x-unknown-namespace::button>Submit</x-unknown-namespace::button></div>`;
process(actual, { root: './test/templates', strict: false })
.then(html => {
expect(html).toBe(actual);
});
});
test('Returns node as-is when namespace is empty (strict mode disabled)', async () => {
const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>`;
process(actual,
{
root: './test/templates',
strict: false,
namespaces: [
{
name: 'empty-namespace',
root: './test/templates/empty-namespace',
}
]
}
)
.then(html => {
expect(html).toBe(actual);
});
});
test('Returns node as-is when x-tag is not found (strict mode disabled)', async () => {
const actual = `<div><x-button>Submit</x-button></div>`;
process(actual, { root: './test/templates/empty-root', strict: false })
.then(html => {
expect(html).toBe(actual);
});
});
test('Returns node as-is when component is not found (strict mode disabled)', async () => {
const actual = `<div><component src="not-found.html">Submit</component></div>`;
process(actual, { tag: 'component', strict: false })
.then(html => {
expect(html).toBe(actual);
});
});