Fix applyAsync from not evaluating expression in tests

See https://github.com/angular/angular.js/issues/10788#issuecomment-70376834
which explains that applyAsync is scheduled to evaluate in the next tick, but
this is managed by $browser. Therefore we can manually flush the trigger
This commit is contained in:
Alasdair Smith 2018-02-22 13:28:16 +00:00
parent 791c126df6
commit 29410b7aab

View file

@ -18,7 +18,7 @@ define ['ide/editor/directives/cmEditor'], () ->
expect(@richTextInit).to.have.been.called expect(@richTextInit).to.have.been.called
it 'attaches to CM', () -> it 'attaches to CM', () ->
inject ($compile, $rootScope) -> inject ($compile, $rootScope, $browser) ->
getSnapshot = sinon.stub() getSnapshot = sinon.stub()
detachFromCM = sinon.stub() detachFromCM = sinon.stub()
attachToCM = sinon.stub() attachToCM = sinon.stub()
@ -30,7 +30,9 @@ define ['ide/editor/directives/cmEditor'], () ->
$compile('<div cm-editor sharejs-doc="sharejsDoc"></div>')($rootScope) $compile('<div cm-editor sharejs-doc="sharejsDoc"></div>')($rootScope)
$rootScope.$digest() $rootScope.$digest()
$rootScope.$digest() # Trigger $applyAsync to evaluate the expression, normally done in the
# next tick
$browser.defer.flush()
expect(detachFromCM).to.have.been.called expect(detachFromCM).to.have.been.called
expect(getSnapshot).to.have.been.called expect(getSnapshot).to.have.been.called