[Please ignore this idea and focus on the reply. It explains why we were seeing setup and teardown called out of order and why we were under the impression that qunit-fixture was designed poorly. Cheers!]
(Preface: I'm a relative new-comer to QUnit. I apologize if the following aspects of qunit-fixture have been discussed ad nauseam. I searched on google, stackoverflow--and of course here--and found nothing similar.)
qunit-fixture is obviously a key aspect of QUnit and it does its job of preventing pollution just fine. However, I find myself wanting to leverage qunit-fixture in test setup as I tend to have very similar usage of qunit-fixture across my tests within a module. This of course does not work since QUnit uses--e.g., given three registered tests within a module--the convention of setup / setup / setup / test1 / test2 / test3 / teardown / teardown / teardown and thus requires usage of qunit-fixture only within the context of a test.
I was wondering if anyone working on QUnit has considered modifying setup to perhaps have a special "context" jQuery object passed in to setup that the programmer could then use to insert his or her HTML. The context object could then be inserted into qunit-fixture at the beginning of each test assuming the context object is non-empty...E.g.:
var setupFunction = function () {
// Retrieve the context object into which my HTML can be inserted.
var context = this["context"];
context.append($(<big blob of HTML>));
};
test("test1", function () {
var context = this["context"];
// Perform tests...Context is inserted into qunit-fixture at this point (immediately before the call to my test function).
});
This would (as I see it) allow the existing setup/teardown architecture to continue but also allow me to put almost all of my setup code where it belongs--in the registered setup function. One could also go the route of having the programmer write to context and just inserting that into qunit-fixture before executing the associated test:
var setupFunction = function () {
// Retrieve the context object into which my HTML can be inserted.
this["context"] = $(<big blob of HTML>);
};
test("test1", function () {
var context = this["context"];
// Perform tests...Context is already inserted into qunit-fixture at this point (immediately before the call to my test function).
});