是否建议将Ember.testing = true设置为单元测试? [英] Is it recommended to set Ember.testing = true for unit tests?
问题描述
有关此功能的使用情况的官方行?这似乎对我们的应用程序有很大的积极影响,但我怀疑大多数人都不知道。
是您应该在测试中设置 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屋!