@@ -2,7 +2,8 @@ import ns from 'web-namespaces';
22import h from 'hastscript' ;
33import s from 'hastscript/svg' ;
44
5- import { serializeNodeToHtmlString } from './utils' ;
5+ import serializeNodeToHtmlString from './utils' ;
6+
67import toDOM from './index' ;
78
89describe ( 'hast-util-to-dom' , ( ) => {
@@ -27,9 +28,7 @@ describe('hast-util-to-dom', () => {
2728 } ) ;
2829
2930 it ( 'creates a root node with a doctype' , ( ) => {
30- const doctype = '<!DOCTYPE html>' ;
31-
32- let actual = serializeNodeToHtmlString ( toDOM ( {
31+ const actual = serializeNodeToHtmlString ( toDOM ( {
3332 type : 'root' ,
3433 children : [ {
3534 type : 'doctype' ,
@@ -54,10 +53,6 @@ describe('hast-util-to-dom', () => {
5453 } ] ,
5554 } ) ) ;
5655
57- if ( actual . charAt ( doctype . length ) === '\n' ) {
58- actual = actual . slice ( 0 , doctype . length ) + actual . slice ( doctype . length + 1 ) ;
59- }
60-
6156 expect ( actual ) . toEqual ( '<!DOCTYPE html><html><head></head><body></body></html>' ) ;
6257 } ) ;
6358
@@ -114,37 +109,25 @@ describe('hast-util-to-dom', () => {
114109 { namespace : ns . svg } ,
115110 ) ) ;
116111
117- expect ( actual ) . toEqual ( '<g id="foo" class="bar"><circle></circle ></g>' ) ;
112+ expect ( actual ) . toEqual ( '<g xmlns="http://www.w3.org/2000/svg" id="foo" class="bar"><circle/ ></g>' ) ;
118113 } ) ;
119114
120115 it ( 'creates an input node with some attributes' , ( ) => {
121- let actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
116+ const actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
122117 disabled : true ,
123118 value : 'foo' ,
124119 } ) ) ) ;
125120
126- actual = actual . replace ( / d i s a b l e d = " " / , 'disabled="disabled"' ) ;
127-
128- if ( actual . slice ( - 3 ) === ' />' ) {
129- actual = `${ actual . slice ( 0 , - 3 ) } >` ;
130- }
131-
132- expect ( actual ) . toEqual ( '<input disabled="disabled" value="foo">' ) ;
121+ expect ( actual ) . toEqual ( '<input disabled="" value="foo" />' ) ;
133122 } ) ;
134123
135124 it ( 'creates an checkbox where `checked` must be set as a property' , ( ) => {
136- let actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
125+ const actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
137126 type : 'checkbox' ,
138127 checked : true ,
139128 } ) ) ) ;
140129
141- actual = actual . replace ( / c h e c k e d = " " / , 'checked="checked"' ) ;
142-
143- if ( actual . slice ( - 3 ) === ' />' ) {
144- actual = `${ actual . slice ( 0 , - 3 ) } >` ;
145- }
146-
147- expect ( actual ) . toEqual ( '<input type="checkbox" checked="checked">' ) ;
130+ expect ( actual ) . toEqual ( '<input type="checkbox" checked="" />' ) ;
148131 } ) ;
149132
150133 it ( 'handles falsey booleans correctly' , ( ) => {
@@ -168,16 +151,11 @@ describe('hast-util-to-dom', () => {
168151
169152 it ( 'handles comma-separated attributes correctly' , ( ) => {
170153 const img = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=' ;
171-
172- let actual = serializeNodeToHtmlString ( toDOM ( h ( 'img' , {
154+ const actual = serializeNodeToHtmlString ( toDOM ( h ( 'img' , {
173155 srcSet : [ `${ img } 1x` , `${ img } 2x` ] ,
174156 } ) ) ) ;
175157
176- if ( actual . slice ( - 3 ) === ' />' ) {
177- actual = `${ actual . slice ( 0 , - 3 ) } >` ;
178- }
179-
180- expect ( actual ) . toEqual ( `<img srcset="${ img } 1x, ${ img } 2x">` ) ;
158+ expect ( actual ) . toEqual ( `<img srcset="${ img } 1x, ${ img } 2x" />` ) ;
181159 } ) ;
182160
183161 it ( 'creates a doctype node' , ( ) => {
@@ -268,12 +246,12 @@ describe('hast-util-to-dom', () => {
268246 expect ( actual ) . toEqual ( '<title>Hi</title><h2>Hello world!</h2>' ) ;
269247 } ) ;
270248
271- it ( 'should support an inferred namespace' , ( ) => {
249+ it ( 'should support a given namespace' , ( ) => {
272250 const actual = serializeNodeToHtmlString (
273251 toDOM ( { type : 'root' , children : [ h ( 'html' ) ] } , { namespace : 'http://example.com' } ) ,
274252 ) ;
275253
276- expect ( actual ) . toEqual ( '<html></html >' ) ;
254+ expect ( actual ) . toEqual ( '<html xmlns="http://example.com"/ >' ) ;
277255 } ) ;
278256
279257 describe ( 'booleanish property' , ( ) => {
0 commit comments