小编Fun*_*lls的帖子

使用 Jasmine 进行单元测试返回 TypeError:this.changeDetectorReference.markForCheck 不是函数

我正在为 Angular 管道编写测试。该管道具有注入的 ChangeDetectorRef 并this.changeDetectorRef.markForCheck()在函数中调用。

但是,当我编写并运行单元测试时,它失败并出现错误TypeError: this.changeDetectorReference.markForCheck is not a function

请问我该如何解决这个问题?代码块下方

百分比.pipe.ts

@Pipe({
  name: 'percent',
  pure: false
})
export class PercentPipe extends BasePercentPipe implements PipeTransform, OnDestroy {
  private onDestroy$: Subject<boolean>;
  private subscription: Subscription;
  private latestValue: any;

  constructor(private gbTranslateService: GbTranslateService, private changeDetectorReference: ChangeDetectorRef, @Inject(LOCALE_ID) locale: string) {
    super(locale);
    this.onDestroy$ = new Subject<boolean>();
  }

  public ngOnDestroy(): void {
    this.changeDetectorReference.detach();
    this.onDestroy$.next(true);
    this.onDestroy$.complete();
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }

  transform(value: any, digitsInfo?: string, locale?: string): any {

    if (value !== …
Run Code Online (Sandbox Code Playgroud)

jasmine angular angular-changedetection

6
推荐指数
0
解决办法
723
查看次数

标签 统计

angular ×1

angular-changedetection ×1

jasmine ×1