it 'computes correctly when on & off have a list at cronRange[4]', ->
@component.set('cronRanges', [Ember.Object.create({
on: "* * * 3 3,1,5"
off: "* * * 3 3,1,5"
})])
@component.set('dayOfWeek', 2)
expect(@component.get('inRange')).to.be.false
@component.set('dayOfWeek', 5)
expect(@component.get('inRange')).to.be.true
@component.set('dayOfWeek', 1)
expect(@component.get('inRange')).to.be.true
@component.set('dayOfWeek', 3)
expect(@component.get('inRange')).to.be.true
这是一个Ember单元测试,失败的错误是该问题的标题。
如果您使用的是ember,请尝试在ember.run =>中包装异步调用,请阅读此
我所理解的是,如果您将某些@set(..,..)
设置为@store()
,在单元测试中并获得此错误,则应使用Ember.run =>
另外,请记住箭头必须是胖箭头(我曾经使用->
而不是=>
犯了一个错误),这是因为JavaScript范围,如果您有兴趣,请阅读。
解决方案:观察我刚刚添加了第2行
it 'computes correctly when on & off have a list at cronRange[4]', ->
Ember.run =>
@component.set('cronRanges', [Ember.Object.create({
on: "* * * 3 3,1,5"
off: "* * * 3 3,1,5"
})])
@component.set('dayOfWeek', 2)
expect(@component.get('inRange')).to.be.false
@component.set('dayOfWeek', 5)
expect(@component.get('inRange')).to.be.true
@component.set('dayOfWeek', 1)
expect(@component.get('inRange')).to.be.true
@component.set('dayOfWeek', 3)
expect(@component.get('inRange')).to.be.true