我一直在工作本教程 http://www.sitepoint.com/angularjs-testing-tips-bootstrap-blocks-routes-events-animations/并在谷歌上进行了令人作呕的搜索,但我似乎无法得到看似微不足道的东西ngAnimate
单元测试运行。
I have ngAnimate
在应用程序中运行良好。所有 Angular 核心库的版本均为 1.4.7。
Module
angular.module 'MyAnimation', [ 'ngAnimate' ]
.animation '.added-class', ->
addClass: (element, className, done) ->
console.log 'add class triggered'
element.css 'opacity', '0.5'
done()
Test
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
功能也很好,但一事无成。帮助?