Skip to content

Commit

Permalink
Merge pull request jasmine#594 from plukevdh/reporter-reset
Browse files Browse the repository at this point in the history
HTML Reporter reset previous DOM when re-initialized
  • Loading branch information
sheelc committed Jun 7, 2014
2 parents 13e0dd2 + 07cce0b commit 7d3de92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/html/HtmlReporterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ describe("New HtmlReporter", function() {
expect(versionText).toEqual(j$.version);
});

it("builds a single reporter even if initialized multiple times", function() {
var env = new j$.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.initialize();
reporter.initialize();

expect(container.querySelectorAll("div.html-reporter").length).toEqual(1);
});

it("starts the timer when jasmine begins", function() {
var env = new jasmine.Env(),
startTimerSpy = jasmine.createSpy("start-timer-spy"),
Expand Down
10 changes: 10 additions & 0 deletions src/html/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jasmineRequire.HtmlReporter = function(j$) {
symbols;

this.initialize = function() {
clearPrior();
htmlReporterMain = createDom('div', {className: 'html-reporter'},
createDom('div', {className: 'banner'},
createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}),
Expand Down Expand Up @@ -220,6 +221,15 @@ jasmineRequire.HtmlReporter = function(j$) {
return getContainer().querySelector('.html-reporter ' + selector);
}

function clearPrior() {
// return the reporter
var oldReporter = find('');

if(oldReporter) {
getContainer().removeChild(oldReporter);
}
}

function createDom(type, attrs, childrenVarArgs) {
var el = createElement(type);

Expand Down

0 comments on commit 7d3de92

Please sign in to comment.