有没有办法运行Ember.Testing验收测试与假定时器? [英] Is there a way to run Ember.Testing acceptance tests with fake timers?

查看:219
本文介绍了有没有办法运行Ember.Testing验收测试与假定时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在EmberJS的项目中进行一系列验收测试(qUnit与EmberJS助手)。现在,我试图尽可能优化这些测试,因为等待10分钟,每次运行只是不太好。



有些测试,我们实际上需要等待一些事情发生:一个计时器用完,一分钟通过时钟更新等。



我尝试使用sinonjs与faketimers,但这似乎是弄乱了ember运行循环以及与应用程序或测试相关的setInterval / setTimeout的任何其他用法。



我正在寻找一种将测试与这样的功能。我会考虑的选项是:




  • 使补丁进入Ember / Ember.Testing或Sinon

  • 使用另一个faketimer方法(除了sinon)

  • 手工伪装成Date对象以处理某种非侵入式假定时器



现在,我想有人必须已经面对了,所以在我得出任何结论之前,我需要问:这是一种建议的方法吗?



谢谢!

解决方案

我们对此问题的特殊解决方法是将常数值从控制器/路线并将其放入App的命名空间,然后在测试期间更改。

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

//如果测试模式,更改一吨东西
//您还可以在创建应用程序时使用不同的配置哈希
if(Ember.testing){
Em.set(App,'someTimerLength',1);
}



引用应用命名空间的随机代码



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

这是一个丑陋的例子,但显示了我们如何做: http://emberjs.jsbin.com/wipo/41/edit


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!

解决方案

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

这篇关于有没有办法运行Ember.Testing验收测试与假定时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆