diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 5e8f1678..9330bb70 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -5055,10 +5055,12 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar(value.toString()); } else if (typeof value === 'function') { this.emitScalar('Function'); - } else if (value.nodeType === 1) { - this.emitDomElement(value); - } else if (typeof value.nodeType === 'number') { - this.emitScalar('HTMLNode'); + } else if (j$.isDomNode(value)) { + if (value.tagName) { + this.emitDomElement(value); + } else { + this.emitScalar('HTMLNode'); + } } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); } else if (j$.isSet(value)) { @@ -5249,15 +5251,29 @@ getJasmineRequireObj().pp = function(j$) { }; PrettyPrinter.prototype.emitDomElement = function(el) { - var closingTag = ''; + var tagName = el.tagName.toLowerCase(), + attrs = el.attributes, + i, + len = attrs.length, + out = '<' + tagName, + attr; - if (el.innerHTML === '') { - this.append(el.outerHTML.replace(closingTag, '')); - } else { - var tagEnd = el.outerHTML.indexOf('>'); - this.append(el.outerHTML.substring(0, tagEnd + 1)); - this.append('...' + closingTag); + for (i = 0; i < len; i++) { + attr = attrs[i]; + out += ' ' + attr.name; + + if (attr.value !== '') { + out += '="' + attr.value + '"'; + } } + + out += '>'; + + if (el.childElementCount !== 0 || el.textContent !== '') { + out += '...'; + } + + this.append(out); }; PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) { diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index ed101eda..f2a0f6d9 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -132,6 +132,10 @@ describe("jasmineUnderTest.pp", function () { }, bar: [1, 2, 3]})).toEqual("Object({ foo: Function, bar: [ 1, 2, 3 ] })"); }); + it("should stringify objects that almost look like DOM nodes", function() { + expect(jasmineUnderTest.pp({nodeType: 1})).toEqual("Object({ nodeType: 1 })"); + }); + it("should truncate objects with too many keys", function () { var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH; var long = {a: 1, b: 2, c: 3}; diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 39b85e56..cb738d28 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -34,10 +34,12 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar(value.toString()); } else if (typeof value === 'function') { this.emitScalar('Function'); - } else if (value.nodeType === 1) { - this.emitDomElement(value); - } else if (typeof value.nodeType === 'number') { - this.emitScalar('HTMLNode'); + } else if (j$.isDomNode(value)) { + if (value.tagName) { + this.emitDomElement(value); + } else { + this.emitScalar('HTMLNode'); + } } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); } else if (j$.isSet(value)) {