2016-12-13 64 views
0
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单元测试,失败的错误是此问题的标题。确保在此测试中调用done()回调

回答

0

如果你使用的灰烬,尝试在Ember.run包装异步调用=>read this

我的理解是,如果你设置的东西@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