Ensure the done() callback is being called in this test

自闭症网瘾萝莉.ら 提交于 2019-12-25 04:24:08

问题


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

this is an ember unit test that fails with the error that is the is the title of this question.


回答1:


If you're using Ember, try wrapping async calls in Ember.run => read this

What I understood is, if you're setting something @set(..,..) to the @store(), in the unit tests, and get this error, then you should use Ember.run =>

Also, remember the arrow has to be a fat arrow, (i made that mistake once of using -> instead of =>)it's because of javascript scope, read up on it if you are interested.

Solution: observe that I just added line # 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


来源:https://stackoverflow.com/questions/41132346/ensure-the-done-callback-is-being-called-in-this-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!