Skip to content

Commit

Permalink
Change fixture reset behavior
Browse files Browse the repository at this point in the history
On load, set clone qunit-fixture element and set config.fixture equal to
that. Change the reset function to replace the entire qunit-fixture
element with a deep copy of the clone. Essentially, cache a clean copy of
the fixture node on load and replace subsequent fixture nodes with that.

Added tests to check if properties on the fixture are cleared between
tests.
  • Loading branch information
conzett committed Feb 1, 2012
1 parent 0712230 commit b9010d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions qunit/qunit.js
Expand Up @@ -564,15 +564,15 @@ extend(QUnit, {
/**
* Resets the test setup. Useful for tests that modify the DOM.
*
* If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
* If jQuery is available, uses jQuery's replaceWith(), otherwise use replaceChild
*/
reset: function() {
if ( window.jQuery ) {
jQuery( "#qunit-fixture" ).html( config.fixture );
} else {
var main = id( 'qunit-fixture' );
jQuery( "#qunit-fixture" ).replaceWith( config.fixture.outerHTML );
} else {
main = id( 'qunit-fixture' );
if ( main ) {
main.innerHTML = config.fixture;
main.parentNode.replaceChild(config.fixture.cloneNode(true), main);
}
}
},
Expand Down Expand Up @@ -779,7 +779,7 @@ QUnit.load = function() {

var main = id('qunit-fixture');
if ( main ) {
config.fixture = main.innerHTML;
config.fixture = main.cloneNode(true);
}

if (config.autostart) {
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Expand Up @@ -313,9 +313,11 @@ if (typeof document !== "undefined") {
module("fixture");
test("setup", function() {
document.getElementById("qunit-fixture").innerHTML = "foobar";
document.getElementById("qunit-fixture").setAttribute('title','foobar');
});
test("basics", function() {
equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" );
equal( document.getElementById("qunit-fixture").getAttribute('title'), null, "properties automatically reset" );
});

}
Expand Down

0 comments on commit b9010d4

Please sign in to comment.