问题
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