Skip to content

Commit 73e94a8

Browse files
committed
Add tests to verify parser behavior on top-level and trailing text nodes.
1 parent d13136c commit 73e94a8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/parse.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,65 @@ test('parse', function (t) {
292292
{ type: 'text', content: ' 10 ' },
293293
]
294294
}], 'should not give voidElements children');
295+
296+
html = '<div></div>\n';
297+
parsed = HTML.parse(html);
298+
t.deepEqual(parsed, [{
299+
type: 'tag',
300+
name: 'div',
301+
attrs: {},
302+
voidElement: false,
303+
children: []
304+
},{
305+
type: 'text', content: '\n'
306+
}], 'should not explode on trailing whitespace');
307+
308+
html = '<div>Hi</div> There ';
309+
parsed = HTML.parse(html);
310+
t.deepEqual(parsed, [{
311+
type: 'tag',
312+
name: 'div',
313+
attrs: {},
314+
voidElement: false,
315+
children: [
316+
{ type: 'text', content: 'Hi' }
317+
]
318+
},{
319+
type: 'text', content: ' There '
320+
}], 'should handle trailing text nodes at the top-level');
321+
322+
html = '<div>Hi</div> There <span>something</span> <a></a>else ';
323+
parsed = HTML.parse(html);
324+
t.deepEqual(parsed, [{
325+
type: 'tag',
326+
name: 'div',
327+
attrs: {},
328+
voidElement: false,
329+
children: [
330+
{ type: 'text', content: 'Hi' }
331+
]
332+
},{
333+
type: 'text', content: ' There '
334+
},{
335+
type: 'tag',
336+
name: 'span',
337+
attrs: {},
338+
voidElement: false,
339+
children: [
340+
{ type: 'text', content: 'something' }
341+
]
342+
},{
343+
type: 'text', content: ' '
344+
},{
345+
type: 'tag',
346+
name: 'a',
347+
attrs: {},
348+
voidElement: false,
349+
children: []
350+
},{
351+
type: 'text', content: 'else '
352+
}], 'should handle text nodes in the middle of tags at the top-level');
353+
295354
t.end();
296355
});
297356

0 commit comments

Comments
 (0)