File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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&<>"\t\n\r </title>'
9+ ) ;
10+
11+ const htmlTitle = htmlDoc . querySelector ( 'title' ) ;
12+ htmlTitle . innerHTML = '<a>sub element</a>' ;
13+ assert (
14+ htmlTitle . innerHTML ,
15+ '<a>sub element</a>'
16+ ) ;
17+ assert (
18+ htmlDoc . toString ( ) ,
19+ '<title><a>sub element</a></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&<>"\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 ) ;
You can’t perform that action at this time.
0 commit comments