Permalink
Browse files

Merge pull request #594 from plukevdh/reporter-reset

HTML Reporter reset previous DOM when re-initialized
  • Loading branch information...
2 parents 13e0dd2 + 07cce0b commit 7d3de92cefcfd0c8f3d79a233212c066aca100fa @sheelc sheelc committed Jun 7, 2014
Showing with 27 additions and 0 deletions.
  1. +17 −0 spec/html/HtmlReporterSpec.js
  2. +10 −0 src/html/HtmlReporter.js
@@ -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"),
View
@@ -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'}),
@@ -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);

0 comments on commit 7d3de92

Please sign in to comment.