From 5d9582b5604d408b85479f908407fc7be3fbd33e Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Mon, 11 May 2015 21:11:18 +0200 Subject: [PATCH] Fixed problem where every children would be dotted out, now we just add three dots for all of the children --- lib/index.js | 68 ++++++++++++++++++++++-------------------- test/unexpected-dom.js | 4 +-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/lib/index.js b/lib/index.js index c95a08d8..276f360f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { @@ -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'); diff --git a/test/unexpected-dom.js b/test/unexpected-dom.js index 6c74b952..f8b848d3 100644 --- a/test/unexpected-dom.js +++ b/test/unexpected-dom.js @@ -827,7 +827,7 @@ describe('unexpected-dom', function () { expect(function () { expect(document, 'queried for', 'div', 'to have length', 1); }, 'to throw', - 'expected ......... queried for \'div\' to have length 1\n' + + 'expected ... queried for \'div\' to have length 1\n' + ' expected NodeList[
,
,
] to have length 1\n' + ' expected 3 to be 1' ); @@ -859,7 +859,7 @@ describe('unexpected-dom', function () { expect(function () { expect(document, 'to contain no elements matching', '.foo'); - }, 'to throw', 'expected ...... to contain no elements matching \'.foo\'\n' + + }, 'to throw', 'expected ... to contain no elements matching \'.foo\'\n' + '\n' + '[\n' + '
, // should be removed\n' +