【发布时间】:2016-01-29 02:08:24
【问题描述】:
我一直在 this tutorial 工作,并在 Google 上搜索过令人作呕的东西,但我似乎无法获得看似微不足道的 ngAnimate 单元测试正在运行。
我的 ngAnimate 在应用程序中运行良好。所有 Angular 核心库都是 1.4.7 版本。
模块
angular.module 'MyAnimation', [ 'ngAnimate' ]
.animation '.added-class', ->
addClass: (element, className, done) ->
console.log 'add class triggered'
element.css 'opacity', '0.5'
done()
测试
describe 'MyAnimation', ->
beforeEach -> module 'ngAnimate'
beforeEach -> module 'ngAnimateMock'
beforeEach -> module 'MyAnimation'
it 'animates', -> inject ($animate, $rootScope, $rootElement) ->
$animate.enabled(true)
divElement = angular.element '<div>my div</div>'
# Kick off initial digest loop in which no animations are run.
$rootScope.$digest()
# Trigger animation.
$animate.addClass divElement, 'added-class'
$rootScope.$digest()
# Tried this, doesn't seem to do anything.
# $animate.flush()
# Results in AssertionError: expected '' to equal '0.5'
expect(divElement.css('opacity')).to.eq '0.5'
我确定该模块已包含在测试中,但触发 $animate.enter 甚至无法获得我的 log 输出。
我也尝试过使用其他 $animate 函数,但无济于事。帮忙?
【问题讨论】:
标签: angularjs unit-testing coffeescript ng-animate