2017-06-20 128 views
0

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

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); 
     } 
    } 
} 

有谁知道我该怎么做? 谢谢。

回答

0

在此blog中提供了2种方法,一种是手动调用它,另一种是使用包装来通过框架触发它