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

人走茶凉 提交于 2019-12-11 08:34:05

问题


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:

  • making patches into Ember / Ember.Testing or Sinon
  • using another faketimer approach (besides sinon)
  • manually faking into the Date object to work on some kind of non-intrusive fake timer

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!


回答1:


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



来源:https://stackoverflow.com/questions/25333535/is-there-a-way-to-run-ember-testing-acceptance-tests-with-fake-timers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!