From ee5905d2377efa91633aa2a5dd39afa7a218898d Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 12 Nov 2009 16:13:44 -0500 Subject: [PATCH] Fix html escaping of matcher failure messages. --- lib/TrivialReporter.js | 4 +--- spec/suites/TrivialReporterSpec.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js index e0e1589..8219d4a 100644 --- a/lib/TrivialReporter.js +++ b/lib/TrivialReporter.js @@ -89,9 +89,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { for (var i = 0; i < resultItems.length; i++) { var result = resultItems[i]; if (result.passed && !result.passed()) { - var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'}); - resultMessageDiv.innerHTML = result.message; // todo: lame; mend - specDiv.appendChild(resultMessageDiv); + specDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); } } diff --git a/spec/suites/TrivialReporterSpec.js b/spec/suites/TrivialReporterSpec.js index 1660c51..2fcc2ca 100644 --- a/spec/suites/TrivialReporterSpec.js +++ b/spec/suites/TrivialReporterSpec.js @@ -122,6 +122,19 @@ describe("TrivialReporter", function() { var divs = body.getElementsByTagName("div"); expect(divs[3].innerHTML).toEqual("Expected 'a' to be null, but it was not"); }); + + it("should add the failure message to the DOM (non-toEquals matchers)", function() { + expectationResult = new jasmine.ExpectationResult({ + matcherName: "toBeNull", passed: false, message: "Expected '1 < 2' to e null, & it was not" + }); + + spyOn(results, 'getItems').andReturn([expectationResult]); + + trivialReporter.reportSpecResults(spec); + + var divs = body.getElementsByTagName("div"); + expect(divs[3].innerHTML).toEqual("Expected '1 < 2' to <b>e null, & it was not"); + }); }); });