Alpha
Alpha

Reputation: 7868

Is there a way to run Ember.Testing acceptance tests with fake timers?

I'm working on a project in EmberJS that has a set of acceptance tests (qUnit with EmberJS helpers). Now, I'm trying to optimize those tests as much as possible because waiting 10 minutes for every run is just not nice.

Some tests that we have actually need to wait for some things to happen: a timer to run out, a minute to pass for the clocks to update, etc.

I tried using sinonjs with faketimers, but this seems to mess up the ember run loop and any other usage of setInterval / setTimeout that is related to the application or tests.

I'm looking for a way to integrate the tests with such functionality. Options I would consider are:

Now, I guess that somebody must have face this already, so before I jump to any conclusions I needed to ask: is there a recommended approach to this situation?

Thanks!

Upvotes: 1

Views: 635

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

Our particular solution to this problem was to pull the constant values out of the controllers/routes and put it into the App's namespace, then change it during testing.

App = Em.Application.create({
  someTimerLength:2000
});

// if testing mode, change a ton of things 
// you could also use a different config hash when creating the app
if(Ember.testing){
  Em.set(App,'someTimerLength', 1);  
}

Random code referencing the app namespace

  Ember.run.later(function(){
    resolve(['red', 'yellow', 'blue']);
  }, App.someTimerLength);

Here's a ugly example, but shows how we do it: http://emberjs.jsbin.com/wipo/41/edit

Upvotes: 1

Related Questions