@@ -2,7 +2,8 @@ import ns from 'web-namespaces';
2
2
import h from 'hastscript' ;
3
3
import s from 'hastscript/svg' ;
4
4
5
- import { serializeNodeToHtmlString } from './utils' ;
5
+ import serializeNodeToHtmlString from './utils' ;
6
+
6
7
import toDOM from './index' ;
7
8
8
9
describe ( 'hast-util-to-dom' , ( ) => {
@@ -27,9 +28,7 @@ describe('hast-util-to-dom', () => {
27
28
} ) ;
28
29
29
30
it ( 'creates a root node with a doctype' , ( ) => {
30
- const doctype = '<!DOCTYPE html>' ;
31
-
32
- let actual = serializeNodeToHtmlString ( toDOM ( {
31
+ const actual = serializeNodeToHtmlString ( toDOM ( {
33
32
type : 'root' ,
34
33
children : [ {
35
34
type : 'doctype' ,
@@ -54,10 +53,6 @@ describe('hast-util-to-dom', () => {
54
53
} ] ,
55
54
} ) ) ;
56
55
57
- if ( actual . charAt ( doctype . length ) === '\n' ) {
58
- actual = actual . slice ( 0 , doctype . length ) + actual . slice ( doctype . length + 1 ) ;
59
- }
60
-
61
56
expect ( actual ) . toEqual ( '<!DOCTYPE html><html><head></head><body></body></html>' ) ;
62
57
} ) ;
63
58
@@ -114,37 +109,25 @@ describe('hast-util-to-dom', () => {
114
109
{ namespace : ns . svg } ,
115
110
) ) ;
116
111
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>' ) ;
118
113
} ) ;
119
114
120
115
it ( 'creates an input node with some attributes' , ( ) => {
121
- let actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
116
+ const actual = serializeNodeToHtmlString ( toDOM ( h ( 'input' , {
122
117
disabled : true ,
123
118
value : 'foo' ,
124
119
} ) ) ) ;
125
120
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" />' ) ;
133
122
} ) ;
134
123
135
124
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' , {
137
126
type : 'checkbox' ,
138
127
checked : true ,
139
128
} ) ) ) ;
140
129
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="" />' ) ;
148
131
} ) ;
149
132
150
133
it ( 'handles falsey booleans correctly' , ( ) => {
@@ -168,16 +151,11 @@ describe('hast-util-to-dom', () => {
168
151
169
152
it ( 'handles comma-separated attributes correctly' , ( ) => {
170
153
const img = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=' ;
171
-
172
- let actual = serializeNodeToHtmlString ( toDOM ( h ( 'img' , {
154
+ const actual = serializeNodeToHtmlString ( toDOM ( h ( 'img' , {
173
155
srcSet : [ `${ img } 1x` , `${ img } 2x` ] ,
174
156
} ) ) ) ;
175
157
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" />` ) ;
181
159
} ) ;
182
160
183
161
it ( 'creates a doctype node' , ( ) => {
@@ -268,12 +246,12 @@ describe('hast-util-to-dom', () => {
268
246
expect ( actual ) . toEqual ( '<title>Hi</title><h2>Hello world!</h2>' ) ;
269
247
} ) ;
270
248
271
- it ( 'should support an inferred namespace' , ( ) => {
249
+ it ( 'should support a given namespace' , ( ) => {
272
250
const actual = serializeNodeToHtmlString (
273
251
toDOM ( { type : 'root' , children : [ h ( 'html' ) ] } , { namespace : 'http://example.com' } ) ,
274
252
) ;
275
253
276
- expect ( actual ) . toEqual ( '<html></html >' ) ;
254
+ expect ( actual ) . toEqual ( '<html xmlns="http://example.com"/ >' ) ;
277
255
} ) ;
278
256
279
257
describe ( 'booleanish property' , ( ) => {
0 commit comments