diff --git a/runner/fixture.js b/runner/fixture.js index f56aa1239..a8048481c 100644 --- a/runner/fixture.js +++ b/runner/fixture.js @@ -20,7 +20,7 @@ import { window, document } from "../src/globals"; var fixture = document.getElementById( "qunit-fixture" ); if ( fixture ) { - config.fixture = fixture.innerHTML; + config.fixture = fixture.cloneNode( true ); } } @@ -33,8 +33,14 @@ import { window, document } from "../src/globals"; } var fixture = document.getElementById( "qunit-fixture" ); - if ( fixture ) { + var resetFixtureType = typeof config.fixture; + if ( resetFixtureType === "string" ) { + + // support user defined values for `config.fixture` fixture.innerHTML = config.fixture; + } else { + const clonedFixture = config.fixture.cloneNode( true ); + fixture.parentNode.replaceChild( clonedFixture, fixture ); } } diff --git a/test/main/test.js b/test/main/test.js index c5be97ede..38a5e1277 100644 --- a/test/main/test.js +++ b/test/main/test.js @@ -24,6 +24,11 @@ if ( typeof document !== "undefined" ) { originalValue = QUnit.config.fixture; values.unshift( originalValue ); values.unshift( originalValue ); + + var customFixtureNode = document.createElement( "span" ); + customFixtureNode.setAttribute( "id", "qunit-fixture" ); + customFixtureNode.setAttribute( "data-baz", "huzzah!" ); + values.push( customFixtureNode ); } ); hooks.beforeEach( function( assert ) { @@ -74,7 +79,7 @@ if ( typeof document !== "undefined" ) { } ); QUnit.test( "setup", function( assert ) { - assert.equal( values.length, 4, "proper sequence" ); + assert.equal( values.length, 5, "proper sequence" ); // setup for next test document.getElementById( "qunit-fixture" ).innerHTML = "foo"; @@ -84,9 +89,9 @@ if ( typeof document !== "undefined" ) { assert.fixtureEquals( { tagName: "div", attributes: { id: "qunit-fixture" }, - content: originalValue + content: originalValue.innerHTML } ); - assert.equal( values.length, 3, "proper sequence" ); + assert.equal( values.length, 4, "proper sequence" ); // setup for next test document.getElementById( "qunit-fixture" ).setAttribute( "data-foo", "blah" ); @@ -96,29 +101,40 @@ if ( typeof document !== "undefined" ) { assert.fixtureEquals( { tagName: "div", attributes: { id: "qunit-fixture" }, - content: originalValue + content: originalValue.innerHTML } ); - assert.equal( values.length, 2, "proper sequence" ); + assert.equal( values.length, 3, "proper sequence" ); } ); - QUnit.test( "user-specified", function( assert ) { + QUnit.test( "user-specified string", function( assert ) { assert.fixtureEquals( { tagName: "div", attributes: { id: "qunit-fixture" }, content: "ar" } ); - assert.equal( values.length, 1, "proper sequence" ); + assert.equal( values.length, 2, "proper sequence" ); // setup for next test document.getElementById( "qunit-fixture" ).innerHTML = "baz"; } ); - QUnit.test( "disabled", function( assert ) { assert.fixtureEquals( { tagName: "div", attributes: { id: "qunit-fixture" }, content: "baz" } ); + assert.equal( values.length, 1, "proper sequence" ); + } ); + + QUnit.test( "user-specified DOM node", function( assert ) { + assert.fixtureEquals( { + tagName: "span", + attributes: { + id: "qunit-fixture", + "data-baz": "huzzah!" + }, + content: "" + } ); assert.equal( values.length, 0, "proper sequence" ); } ); } );