【问题标题】:Is there a way to run Ember.Testing acceptance tests with fake timers?有没有办法用假计时器运行 Ember.Testing 验收测试?
【发布时间】:2014-08-15 20:13:59
【问题描述】:

我正在使用 EmberJS 开发一个项目,该项目具有一组验收测试(带有 EmberJS 助手的 qUnit)。现在,我正在尝试尽可能优化这些测试,因为每次运行等待 10 分钟并不好。

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

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

我正在寻找一种将测试与此类功能集成的方法。我会考虑的选项是:

  • 为 Ember / Ember.Testing 或 Sinon 制作补丁
  • 使用另一种 faketimer 方法(除了 sinon)
  • 手动伪装成 Date 对象以处理某种非侵入式假计时器

现在,我想肯定有人已经面对这个问题了,所以在我得出任何结论之前,我需要问一下:对于这种情况有推荐的方法吗?

谢谢!

【问题讨论】:

    标签: javascript ember.js sinon acceptance-testing


    【解决方案1】:

    我们对这个问题的特殊解决方案是从控制器/路由中提取常量值并将其放入应用程序的命名空间,然后在测试期间对其进行更改。

    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);  
    }
    

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

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

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

    【讨论】:

      猜你喜欢
      • 2010-10-23
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多