diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js
index 6a5ee6cc..a7182895 100644
--- a/lib/jasmine-core/jasmine.js
+++ b/lib/jasmine-core/jasmine.js
@@ -4150,6 +4150,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) {
@@ -4206,6 +4208,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);
@@ -4342,6 +4345,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(': ');
diff --git a/spec/core/matchers/toEqualSpec.js b/spec/core/matchers/toEqualSpec.js
index c3115644..456952ee 100644
--- a/spec/core/matchers/toEqualSpec.js
+++ b/spec/core/matchers/toEqualSpec.js
@@ -534,7 +534,7 @@ describe("toEqual", function() {
var actual = {a: document.createElement('div')},
expected = {a: document.createElement('p')},
- message = 'Expected $.a = HTMLNode to equal HTMLNode.';
+ message = 'Expected $.a =
to equal
.';
expect(compareEquals(actual, expected).message).toEqual(message);
});
@@ -552,7 +552,7 @@ describe("toEqual", function() {
var actual = {a: nodeA},
expected = {a: nodeB},
- message = 'Expected $.a = HTMLNode to equal HTMLNode.';
+ message = 'Expected $.a =
...
to equal
...
.';
expect(compareEquals(actual, expected).message).toEqual(message);
})
@@ -564,7 +564,7 @@ describe("toEqual", function() {
var actual = {a: document.createElement('div')},
expected = {a: {}},
- message = 'Expected $.a = HTMLNode to equal Object({ }).';
+ message = 'Expected $.a =
to equal Object({ }).';
expect(compareEquals(actual, expected).message).toEqual(message);
});
diff --git a/spec/html/PrettyPrintHtmlSpec.js b/spec/html/PrettyPrintHtmlSpec.js
index 336d85f0..caad7513 100644
--- a/spec/html/PrettyPrintHtmlSpec.js
+++ b/spec/html/PrettyPrintHtmlSpec.js
@@ -1,11 +1,23 @@
describe("jasmineUnderTest.pp (HTML Dependent)", function () {
- it("should stringify HTML nodes properly", function() {
- var sampleNode = document.createElement('div');
- sampleNode.innerHTML = 'foo
bar';
+ it("should stringify non-element HTML nodes properly", function() {
+ var sampleNode = document.createTextNode("");
expect(jasmineUnderTest.pp(sampleNode)).toEqual("HTMLNode");
expect(jasmineUnderTest.pp({foo: sampleNode})).toEqual("Object({ foo: HTMLNode })");
});
+ it("should stringify empty HTML elements as their opening tags", function () {
+ var simple = document.createElement('div');
+ simple.className = 'foo';
+ expect(jasmineUnderTest.pp(simple)).toEqual('
');
+ });
+
+ it("should stringify non-empty HTML elements as tags with placeholders", function() {
+ var nonEmpty = document.createElement('div');
+ nonEmpty.className = 'foo';
+ nonEmpty.innerHTML = '
Irrelevant
';
+ expect(jasmineUnderTest.pp(nonEmpty)).toEqual('
...
');
+ });
+
it("should print Firefox's wrapped native objects correctly", function() {
if(jasmine.getEnv().firefoxVersion) {
try { new CustomEvent(); } catch(e) { var err = e; };
diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js
index 9adb4d55..3d70f1a4 100644
--- a/src/core/PrettyPrinter.js
+++ b/src/core/PrettyPrinter.js
@@ -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(': ');