我正在为 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)