如何制作角度动画的测试用例

时间:2018-10-09 00:42:22

标签: angular animation jasmine karma-jasmine angular-animations

我使用业力编写angular2测试用例,但不知道如何测试动画。我试图获取并检查宿主元素的转换属性,但未获得任何结果,“ getCalculateStyle()”方法均无法正常工作。 有什么建议么?

要测试的示例代码:

func2Test() {
    const animations: AnimationMetadata[] = [animate('500ms ease-in', style({transform: `translate3d(100px, 0px, 0px)`}))];
    const myAnimation: AnimationFactory = this.animationBuilder.build(animations);
    const player = myAnimation.create(this.slickTrack.nativeElement);
    player.play();
}

1 个答案:

答案 0 :(得分:1)

我想我找到一个例子

https://github.com/angular/angular/blob/master/packages/animations/browser/test/dsl/animation_spec.ts

it('should fill in missing starting steps when a starting `style()` value is not used',
           () => {
             const steps = [animate(1000, style({width: 999}))];

             const players = invokeAnimationSequence(rootElement, steps);
             expect(players[0].keyframes).toEqual([
               {width: AUTO_STYLE, offset: 0}, {width: 999, offset: 1}
             ]);
           });