Search code examples
ember.jsember-cliember-qunit

One passing Ember integration test breaks the next one: bad teardown block?


I have these two Ember integration tests, A and B. (I have a lot more, but in debugging this I have literally removed every other test in order to isolate the problem. There are 9 tests in the same file as A and I commented the other 8.) If A runs before B, B will fail. If B runs by itself, or before A, it will pass.

From this description it seems pretty clear that A is doing something to the test environment that screws up B. After liberally salting the tests and the production code involved with log messages, however, I'm no closer to figuring out what's up, and I'm hoping someone else can spot if there's an obvious issue.

Right now I'm looking closely at the afterEach blocks in both tests. Here's an outline of what the beforeEach and afterEach blocks look like for test A:

beforeEach: function() {
  server = new Pretender(function() {
    // Pretender setup removed for brevity
  });

  App = startApp();
},
afterEach: function() {
  server.shutdown();
  Ember.run(App, App.destroy);
}

That afterEach is pretty much the stock ember-cli code, but it baffles me a bit. The documentation on Ember.run() suggests it should get a function as an argument, but we're not giving it one here, so I'm not sure how that works. And, should the Pretender shutdown() call be inside the Ember.run (or in its own Ember.run)?

The versions, for the record: ember-cli 0.2.0, Ember 1.10.1.

ETA: The issue goes away when I update to ember-cli 0.2.3 and Ember 1.11.3. Now if only I could figure out the other failing tests we have with that update...


Solution

  • Your setup and teardown looks fine. They are commonly used and are properly defined.

    However, there is (still) open issue on ember-qunit about not tearing down the app properly - take a look here to see the progress.

    As you said, it does not happen in Ember 1.13.