【问题标题】:Ensure the done() callback is being called in this test确保在此测试中调用了 done() 回调
【发布时间】:2016-12-14 07:37:57
【问题描述】:
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 单元测试,错误是这个问题的标题。

【问题讨论】:

    标签: unit-testing ember.js timeout


    【解决方案1】:

    如果您使用的是 Ember,请尝试在 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
    

    【讨论】:

      猜你喜欢
      • 2017-03-12
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 2021-09-13
      • 1970-01-01
      相关资源
      最近更新 更多