Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/17'
Browse files Browse the repository at this point in the history
* origin/pr/17:
  Fixed problem where every children would be dotted out, now we just add three dots for all of the children
  • Loading branch information
Munter committed May 11, 2015
2 parents ab0b42e + 5d9582b commit 70ee597
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
68 changes: 36 additions & 32 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ module.exports = {
},
inspect: function (document, depth, output, inspect) {
for (var i = 0 ; i < document.childNodes.length ; i += 1) {
output.append(inspect(document.childNodes[i], depth - 1));
output.append(inspect(document.childNodes[i]));
}
},
diff: function (actual, expected, output, diff, inspect, equal) {
Expand Down Expand Up @@ -324,43 +324,47 @@ module.exports = {
var elementName = element.nodeName.toLowerCase();
var startTag = stringifyStartTag(element);

var inspectedChildren = [];
if (elementName === 'script') {
var type = element.getAttribute('type');
if (!type || /javascript/.test(type)) {
type = 'javascript';
}
inspectedChildren.push(output.clone().code(element.textContent, type));
} else if (elementName === 'style') {
inspectedChildren.push(output.clone().code(element.textContent, element.getAttribute('type') || 'text/css'));
} else {
for (var i = 0 ; i < element.childNodes.length ; i += 1) {
inspectedChildren.push(inspect(element.childNodes[i]));
}
}

var width = 0;
var multipleLines = inspectedChildren.some(function (o) {
var size = o.size();
width += size.width;
return width > 50 || o.height > 1;
});

output.code(startTag, 'html');
if (element.childNodes.length > 0) {

if (multipleLines) {
output.nl().indentLines();
if (depth === 1) {
output.text('...');
} else {
var inspectedChildren = [];
if (elementName === 'script') {
var type = element.getAttribute('type');
if (!type || /javascript/.test(type)) {
type = 'javascript';
}
inspectedChildren.push(output.clone().code(element.textContent, type));
} else if (elementName === 'style') {
inspectedChildren.push(output.clone().code(element.textContent, element.getAttribute('type') || 'text/css'));
} else {
for (var i = 0 ; i < element.childNodes.length ; i += 1) {
inspectedChildren.push(inspect(element.childNodes[i]));
}
}

inspectedChildren.forEach(function (inspectedChild, index) {
output.i().block(inspectedChild).nl();
var width = 0;
var multipleLines = inspectedChildren.some(function (o) {
var size = o.size();
width += size.width;
return width > 50 || o.height > 1;
});

output.outdentLines();
} else {
inspectedChildren.forEach(function (inspectedChild, index) {
output.append(inspectedChild);
});
if (multipleLines) {
output.nl().indentLines();

inspectedChildren.forEach(function (inspectedChild, index) {
output.i().block(inspectedChild).nl();
});

output.outdentLines();
} else {
inspectedChildren.forEach(function (inspectedChild, index) {
output.append(inspectedChild);
});
}
}
}
output.code(stringifyEndTag(element), 'html');
Expand Down
4 changes: 2 additions & 2 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ describe('unexpected-dom', function () {
expect(function () {
expect(document, 'queried for', 'div', 'to have length', 1);
}, 'to throw',
'expected <!DOCTYPE html><html><head></head><body>.........</body></html> queried for \'div\' to have length 1\n' +
'expected <!DOCTYPE html><html><head></head><body>...</body></html> queried for \'div\' to have length 1\n' +
' expected NodeList[ <div></div>, <div></div>, <div></div> ] to have length 1\n' +
' expected 3 to be 1'
);
Expand Down Expand Up @@ -859,7 +859,7 @@ describe('unexpected-dom', function () {

expect(function () {
expect(document, 'to contain no elements matching', '.foo');
}, 'to throw', 'expected <!DOCTYPE html><html><head></head><body>......</body></html> to contain no elements matching \'.foo\'\n' +
}, 'to throw', 'expected <!DOCTYPE html><html><head></head><body>...</body></html> to contain no elements matching \'.foo\'\n' +
'\n' +
'DOMNodeList[\n' +
' <div class="foo"></div>, // should be removed\n' +
Expand Down

0 comments on commit 70ee597

Please sign in to comment.