1
- import bowser from 'bowser' ;
2
1
import h from 'hastscript' ;
3
2
4
3
import { serializeNodeToHtmlString } from './utils' ;
@@ -54,13 +53,14 @@ describe('hast-util-to-dom', () => {
54
53
} ] ,
55
54
} ] ,
56
55
} ;
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 ) ;
63
62
}
63
+
64
64
expect ( htmlActual ) . toEqual ( htmlExpected ) ;
65
65
} ) ;
66
66
@@ -100,16 +100,15 @@ describe('hast-util-to-dom', () => {
100
100
disabled : true ,
101
101
value : 'foo' ,
102
102
} ) ;
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 ) } >` ;
112
110
}
111
+
113
112
expect ( htmlActual ) . toEqual ( htmlExpected ) ;
114
113
} ) ;
115
114
@@ -123,13 +122,13 @@ describe('hast-util-to-dom', () => {
123
122
it ( 'handles comma-separated attributes correctly' , ( ) => {
124
123
const img = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=' ;
125
124
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 ) } >` ;
132
130
}
131
+
133
132
expect ( htmlActual ) . toEqual ( htmlExpected ) ;
134
133
} ) ;
135
134
0 commit comments