是否建议将Ember.testing = true设置为单元测试? [英] Is it recommended to set Ember.testing = true for unit tests?

查看:98
本文介绍了是否建议将Ember.testing = true设置为单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近开始在我们的茉莉花规范中使用无证的Ember.testing标志,它有效地禁用了自动运行的runloop功能。我们发现,这需要我们更加明确地在运行环境中手动包装代码,但也使我们在规范中更加稳定,因为它们以我们编写规范的方式突出显示问题,并有助于在绑定时记录文档对于被测代码很重要。



有关此功能的使用情况的官方行?这似乎对我们的应用程序有很大的积极影响,但我怀疑大多数人都不知道。

解决方案

是您应该在测试中设置 Ember.testing = true



没有 Ember .testing ,运行循环将自动安排为 setTimeout ,这是您注意到的不稳定来自哪里。



注意:目前,当您激活 Ember.testing 时,您必须以<$ c的结尾为您的测试代码中的许多行添加前缀$ c> Em.run => ,如

  Em.run => obj.set('someProperty',true)

如果你忘了,它会大声抱怨,或当您尝试对其执行断言时,属性/应用状态将不会更新。



也许这会有所改善,但现在不用担心如果您的测试代码撒上运行呼叫。


We've recently started to use the undocumented Ember.testing flag in our jasmine specs which effectively disables the autorun runloop feature. We've found that this requires us to be quite a bit more explicit about manually wrapping code in runloops but has also given us more stability in our specs as it highlights problems in the way we've written the spec and helps to document when bindings are important to the code under test.

Is there an official line on the usage of this feature ? It appears to have had quite a positive impact in our app but I suspect most people aren't aware of it.

解决方案

Yes, you should definitely set Ember.testing = true in your tests.

Without Ember.testing, runloops are scheduled automatically with setTimeout, which is where the instability you're noting comes from.

Note: At the moment, when you activate Ember.testing, you necessarily end up prefixing many of the lines in your test code with Em.run =>, like

Em.run => obj.set('someProperty', true)

If you forget to, it will complain loudly, or properties/app state won't have updated when you try to run assertions against it.

Maybe this will be improved some day, but for now it's nothing to be worried about if your test code is sprinkled with run calls.

这篇关于是否建议将Ember.testing = true设置为单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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