Stop treating objects with a nodeType as if they are DOM Nodes
- Fixes #1638
This commit is contained in:
@@ -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 = '</' + el.tagName.toLowerCase() + '>';
|
||||
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 += '...</' + tagName + '>';
|
||||
}
|
||||
|
||||
this.append(out);
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user