How to use QUnit.module() for setup/teardown of a group of tests?


#1

I have a component to test; the basic tests are working fine, but now I want to start making more organised tests. If I do:

test('can add a thing', function() {
  var component = this.subject();
  component.addThing("apple");
  deepEqual(component.get("things", ["apple"]);
});

then everything is fine. But if I run another test that calls addThing, the apple is still in the array from the first test, so the second test fails (unless I make the tests depend on one another, which is no good).

So what I want to do is something like:

module("adding things", {
  setup: function() {
    this.subject().resetThings();
  }
});

but in the module() call (or if I use QUnit.module()), I can’t call this.subject(), because ‘this’ is the module object itself, not anything related to the component I’m trying to test. Looking at arguments and going up through the call stack, I can’t find any way to get to the currently under-test component; it seems as if ember-qunit isn’t wrapping qunit.module() the way it needs to, but am I missing another way to get at this?