Testing ember nested routes fails


#1

I’m using karma with qUnit (after following this tutorial) to test my Ember application. It’s mostly going well, however I’ve run into a problem that doesn’t make sense.

Given the 2 following tests:

test('can get to products', function() {
  visit('/products/')
    .then(function() {
      ok(find('*'));
    });
});


test('can get to catalogues', function() {
  visit('/products/catalogues')
    .then(function() {
      ok(find('*'));
    });
});

The first will run fine. The test runner gets to /products and finds something.

However, the second test returns an error in the console:

Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run

I turned on transition logs, and the test runner is visiting products.catalogues.index before throwing the error.

Any ideas with this? Or is it simply a bug inside ember’s testing tools?

Both are valid routes defined inside the router…

(Also asked on stack overflow)


#2

I answered on StackOverflow http://stackoverflow.com/a/18787580/172894


#3

@tarasm your answer is to use Ember.run(...) in the route’s #model callback.

Unless the Ember router has gotten smarter recently, returning the result of Ember.run isn’t a general solution. Specifically, if you want model to return a promise to delay transition, Ember.run will hide that promise from the router.

Perhaps visit needs to be smarter about how it needs to work with the run-loop.