Skip to content

Commit 3a8d77e

Browse files
committed
Update representation of void nodes
And, additionally, update the representation of parent nodes without children.
1 parent 78df195 commit 3a8d77e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ function formatNode(node) {
178178
var values = [];
179179
var value;
180180

181-
if (node.children && node.children.length) {
181+
if (node.children) {
182182
log += dim('[') + yellow(node.children.length) + dim(']');
183-
} else {
183+
} else if (typeof node.value === 'string') {
184184
log += dim(': ') + green(JSON.stringify(node.value));
185185
}
186186

test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,33 @@ test('inspect()', function (t) {
206206
'should work with other attributes'
207207
);
208208

209+
t.equal(
210+
strip(inspect({
211+
'type': 'element',
212+
'tagName': 'br',
213+
'children': []
214+
})),
215+
'element[0] [tagName="br"]',
216+
'should work on parent nodes without children'
217+
);
218+
219+
t.equal(
220+
strip(inspect({
221+
'type': 'text',
222+
'value': ''
223+
})),
224+
'text: ""',
225+
'should work on text nodes without value'
226+
);
227+
228+
t.equal(
229+
strip(inspect({
230+
'type': 'thematicBreak'
231+
})),
232+
'thematicBreak',
233+
'should work on void nodes'
234+
);
235+
209236
t.equal(
210237
strip(inspect({
211238
'type': 'foo',

0 commit comments

Comments
 (0)