diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 4b1454b5..64a8213a 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -72,6 +72,12 @@ jasmineRequire.HtmlReporter = function(j$) { } }; + ResultsStateBuilder.prototype.jasmineDone = function(result) { + if (result.failedExpectations) { + this.failureCount += result.failedExpectations.length; + } + }; + function HtmlReporter(options) { var config = function() { return (options.env && options.env.configuration()) || {}; @@ -187,6 +193,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.jasmineDone = function(doneResult) { + stateBuilder.jasmineDone(doneResult); var banner = find('.jasmine-banner'); var alert = find('.jasmine-alert'); var order = doneResult && doneResult.order; diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index d31a3a35..8a8ae4f2 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -1653,6 +1653,61 @@ describe('HtmlReporter', function() { ); }); }); + + it('counts failures that are reported in the jasmineDone event', function() { + const container = document.createElement('div'); + function getContainer() { + return container; + } + const reporter = new jasmineUnderTest.HtmlReporter({ + env: env, + getContainer: getContainer, + createElement: function() { + return document.createElement.apply(document, arguments); + }, + createTextNode: function() { + return document.createTextNode.apply(document, arguments); + }, + addToExistingQueryString: function(key, value) { + return '?' + key + '=' + value; + } + }); + reporter.initialize(); + + reporter.jasmineStarted({ totalSpecsDefined: 1 }); + + const failingSpecResult = { + id: 124, + status: 'failed', + description: 'a failing spec', + fullName: 'a suite inner suite a failing spec', + passedExpectations: [], + failedExpectations: [ + { + message: 'a failure message', + stack: 'a stack trace' + } + ] + }; + + reporter.specStarted(failingSpecResult); + reporter.specDone(failingSpecResult); + reporter.jasmineDone({ + failedExpectations: [ + { + message: 'a failure message', + stack: 'a stack trace' + }, + { + message: 'a failure message', + stack: 'a stack trace' + } + ] + }); + + const alertBar = container.querySelector('.jasmine-alert .jasmine-bar'); + expect(alertBar.innerHTML).toMatch(/1 spec, 3 failures/); + }); }); describe('The overall result bar', function() { diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 840bbcf3..7f69cb57 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -41,6 +41,12 @@ jasmineRequire.HtmlReporter = function(j$) { } }; + ResultsStateBuilder.prototype.jasmineDone = function(result) { + if (result.failedExpectations) { + this.failureCount += result.failedExpectations.length; + } + }; + function HtmlReporter(options) { var config = function() { return (options.env && options.env.configuration()) || {}; @@ -156,6 +162,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.jasmineDone = function(doneResult) { + stateBuilder.jasmineDone(doneResult); var banner = find('.jasmine-banner'); var alert = find('.jasmine-alert'); var order = doneResult && doneResult.order;