1- import bowser from 'bowser' ;
21import h from 'hastscript' ;
32
43import { serializeNodeToHtmlString } from './utils' ;
@@ -54,13 +53,14 @@ describe('hast-util-to-dom', () => {
5453 } ] ,
5554 } ] ,
5655 } ;
57- const htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
58- let htmlExpected = '<!DOCTYPE html><html>< head></head><body></body></html>' ;
59- if ( ! bowser . x ) {
60- if ( bowser . gecko ) {
61- htmlExpected = '<!DOCTYPE html>\n<html><head></head><body></body></html>' ;
62- }
56+ const doctype = '<!DOCTYPE html>' ;
57+ const htmlExpected = ` ${ doctype } < html><head></head><body></body></html>` ;
58+ let htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
59+
60+ if ( htmlActual . charAt ( doctype . length ) === '\n' ) {
61+ htmlActual = htmlActual . slice ( 0 , doctype . length ) + htmlActual . slice ( doctype . length + 1 ) ;
6362 }
63+
6464 expect ( htmlActual ) . toEqual ( htmlExpected ) ;
6565 } ) ;
6666
@@ -100,16 +100,15 @@ describe('hast-util-to-dom', () => {
100100 disabled : true ,
101101 value : 'foo' ,
102102 } ) ;
103- const htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
104- let htmlExpected = '<input disabled="" value="foo">' ;
105- // Specific non-JSDOM environments
106- if ( ! bowser . x ) {
107- if ( bowser . webkit || bowser . blink ) {
108- htmlExpected = '<input disabled="" value="foo" />' ;
109- } else if ( bowser . gecko ) {
110- htmlExpected = '<input disabled="disabled" value="foo" />' ;
111- }
103+ const htmlExpected = '<input disabled="disabled" value="foo">' ;
104+ let htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
105+
106+ htmlActual = htmlActual . replace ( / d i s a b l e d = " " / , 'disabled="disabled"' ) ;
107+
108+ if ( htmlActual . slice ( - 3 ) === ' />' ) {
109+ htmlActual = `${ htmlActual . slice ( 0 , - 3 ) } >` ;
112110 }
111+
113112 expect ( htmlActual ) . toEqual ( htmlExpected ) ;
114113 } ) ;
115114
@@ -123,13 +122,13 @@ describe('hast-util-to-dom', () => {
123122 it ( 'handles comma-separated attributes correctly' , ( ) => {
124123 const img = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=' ;
125124 const tree = h ( 'img' , { srcSet : [ `${ img } 1x` , `${ img } 2x` ] } ) ;
126- const htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
127- let htmlExpected = `<img srcset="${ img } 1x, ${ img } 2x">` ;
128- if ( ! bowser . x ) {
129- if ( bowser . webkit || bowser . blink || bowser . gecko ) {
130- htmlExpected = `<img srcset="${ img } 1x, ${ img } 2x" />` ;
131- }
125+ const htmlExpected = `<img srcset="${ img } 1x, ${ img } 2x">` ;
126+ let htmlActual = serializeNodeToHtmlString ( toDOM ( tree ) ) ;
127+
128+ if ( htmlActual . slice ( - 3 ) === ' />' ) {
129+ htmlActual = `${ htmlActual . slice ( 0 , - 3 ) } >` ;
132130 }
131+
133132 expect ( htmlActual ) . toEqual ( htmlExpected ) ;
134133 } ) ;
135134
0 commit comments