Question

I'm testing an relatively large Ember application (http://wheelmap.org/map) with QUnit and having problems with debounced calls e.g. changing the url to have a permalink of a map view inside the app or doing a manual AJAX request while testing.

I followed the documentation at http://emberjs.com/guides/testing/integration/

Now when I reset the application state by calling App.reset() in the module setup it resets all bindings, etc. to variables and dependant controllers.

module('Map', {
  setup: function() {
    App.reset();
  }
});

This seems to be good to have a clean working environment, but leads to errors where variables are accessiable by Ember.set and Ember.get e.g. this.get('controllers.toolbar'):

Cannot call method 'set' of null

So the first test allways runs great, but further tests break because of debounced function calls from the first test. So what I think I have to do is stop this debounced calls somehow.

Other options would be checking if all needed variables are set in this function calls. But this seems to be cumbersome when adding conditions only for testing.

What do you think?

Thank you in advance!

Was it helpful?

Solution

I found the answer by searching through the RunLoop source files:

Ember.run.cancelTimers()

It's not part of the documentation. Maybe a problem of poor documentation or not beeing part of the public API.

Now I just call it in the module test teardown function:

module('Map', {
  setup: function() {
    // ...
  },
  teardown: function() {
    Ember.run.cancelTimers()
  }
});

OTHER TIPS

We ran into a similar problem and decided to disable debounce during testing.

You can check if in testing mode using if(Ember.testing){...}.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top