Skip to content

Commit 6aa67ee

Browse files
committed
Add tests for title elements
1 parent 8e76ea9 commit 6aa67ee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/html/title-element.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const assert = require('../assert.js').for('HTMLTitleElement');
2+
3+
const {DOMParser, parseHTML} = global[Symbol.for('linkedom')];
4+
5+
const {document: htmlDoc} = parseHTML('<title>abc&<>"\t\n\r\xA0</title>');
6+
assert(
7+
htmlDoc.toString(),
8+
'<title>abc&amp;&lt;&gt;"\t\n\r&nbsp;</title>'
9+
);
10+
11+
const htmlTitle = htmlDoc.querySelector('title');
12+
htmlTitle.innerHTML = '<a>sub element</a>';
13+
assert(
14+
htmlTitle.innerHTML,
15+
'&lt;a&gt;sub element&lt;/a&gt;'
16+
);
17+
assert(
18+
htmlDoc.toString(),
19+
'<title>&lt;a&gt;sub element&lt;/a&gt;</title>'
20+
);
21+
assert(htmlDoc.querySelectorAll('a').length, 0);
22+
23+
const xhtmlDoc = (new DOMParser).parseFromString('<title xmlns="http://www.w3.org/1999/xhtml">abc&<>"\t\n\r\xA0</title>', 'application/xhtml+xml');
24+
assert(
25+
xhtmlDoc.toString(),
26+
'<?xml version="1.0" encoding="utf-8"?><title xmlns="http://www.w3.org/1999/xhtml">abc&amp;&lt;&gt;"\t\n\r\xA0</title>'
27+
);
28+
29+
const xhtmlTitle = xhtmlDoc.querySelector('title');
30+
xhtmlTitle.innerHTML = '<a>sub element</a>';
31+
assert(
32+
xhtmlTitle.innerHTML,
33+
'<a>sub element</a>'
34+
);
35+
assert(
36+
xhtmlDoc.toString(),
37+
'<?xml version="1.0" encoding="utf-8"?><title xmlns="http://www.w3.org/1999/xhtml"><a>sub element</a></title>'
38+
);
39+
assert(xhtmlDoc.querySelectorAll('a').length, 1);

0 commit comments

Comments
 (0)