More informative pretty-printing of DOM elements

[Finishes ##153562618]
This commit is contained in:
Steve Gravrock
2017-12-08 18:53:11 -08:00
committed by Steve Gravrock
parent eb93d38294
commit ac5d8708b9
4 changed files with 48 additions and 6 deletions

View File

@@ -32,6 +32,8 @@ 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 (value instanceof Date) {
@@ -88,6 +90,7 @@ getJasmineRequireObj().pp = function(j$) {
PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitDomElement = j$.unimplementedMethod_;
function StringPrettyPrinter() {
PrettyPrinter.call(this);
@@ -224,6 +227,18 @@ getJasmineRequireObj().pp = function(j$) {
this.append(constructorName + ' [ ' + itemsString + ' ]');
};
StringPrettyPrinter.prototype.emitDomElement = function(el) {
var closingTag = '</' + el.tagName.toLowerCase() + '>';
if (el.innerHTML === '') {
this.append(el.outerHTML.replace(closingTag, ''));
} else {
var tagEnd = el.outerHTML.indexOf(el.innerHTML);
this.append(el.outerHTML.substring(0, tagEnd));
this.append('...' + closingTag);
}
};
StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
this.append(property);
this.append(': ');