【问题标题】:Testing ngOnChanges with SimpleChanges in Angular 2在 Angular 2 中使用 SimpleChanges 测试 ngOnChanges
【发布时间】:2017-06-20 18:44:20
【问题描述】:

我有下面的代码,我需要知道如何在我的测试中使用spyonpreviousValuecurrentValue 来覆盖条件if (cur !== prev && cur === 100)

ngOnChanges(changes: SimpleChanges) {
    if (changes['highlightData'] && !changes['highlightData'].isFirstChange()) {
        const prev: any = changes['highlightData'].previousValue;
        const cur: any = changes['highlightData'].currentValue;

        if (cur !== prev && cur === 100) {
            this._render.setElementClass(this._elementRef.nativeElement, 'animate', true);

            setTimeout(() => {
                this._render.setElementClass(this._elementRef.nativeElement, 'animate', false);
            }, 3000);
        }
    }
}

有人知道我该怎么做吗? 谢谢。

【问题讨论】:

    标签: karma-jasmine angular2-directives angular2-testing


    【解决方案1】:

    这个blog提供了2种方法,一种是手动调用,另一种是使用包装器通过框架触发

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-19
      • 2018-08-19
      • 2018-06-21
      • 2018-06-13
      • 2017-03-27
      • 1970-01-01
      • 2017-04-30
      • 2016-12-20
      相关资源
      最近更新 更多