Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors from debounced function calls in testing ember application

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!

like image 898
Johnny Avatar asked Jan 24 '26 13:01

Johnny


2 Answers

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()
  }
});
like image 188
Johnny Avatar answered Jan 26 '26 12:01

Johnny


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

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

like image 35
Kingpin2k Avatar answered Jan 26 '26 11:01

Kingpin2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!