Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit a68445b

Browse files
committed
test: add template abbreviation
1 parent b447ace commit a68445b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
const parser = new DOMParser()
6+
7+
function parseHTML(html: string) {
8+
return parser.parseFromString(html, 'text/html').body.innerHTML
9+
}
10+
11+
function checkAbbr(template: string, abbrevation: string, expected: string) {
12+
// TODO do some optimzations to make sure template === abbrevation
13+
expect(parseHTML(abbrevation)).toBe(expected)
14+
}
15+
16+
test('template abbreviation', () => {
17+
checkAbbr('<div>hello</div>', '<div>hello', '<div>hello</div>')
18+
checkAbbr(
19+
'<div><div>hello</div></div>',
20+
'<div><div>hello',
21+
'<div><div>hello</div></div>',
22+
)
23+
checkAbbr(
24+
'<div><span>foo</span><span/></div>',
25+
'<div><span>foo</span><span>',
26+
'<div><span>foo</span><span></span></div>',
27+
)
28+
checkAbbr(
29+
'<div><hr/><div/></div>',
30+
'<div><hr><div>',
31+
'<div><hr><div></div></div>',
32+
)
33+
checkAbbr(
34+
'<div><div/><hr/></div>',
35+
'<div><div></div><hr>',
36+
'<div><div></div><hr></div>',
37+
)
38+
39+
checkAbbr('<span/>hello', '<span></span>hello', '<span></span>hello')
40+
})

0 commit comments

Comments
 (0)