我有一个要升级的 angularjs 组件:
import { Directive, ElementRef, Injector, Output, EventEmitter } from '@angular/core';
import { UpgradeComponent } from '@angular/upgrade/static';
@Directive({
selector: 'up'
})
export class UpDirective extends UpgradeComponent {
constructor(elementRef: ElementRef, injector: Injector) {
super('old', elementRef, injector);
}
}
当我运行应用程序时,这个组件工作得很好。
但是,当我尝试测试使用该指令的 Angular 8 组件时,出现以下错误:
NullInjectorError: StaticInjectorError(DynamicTestModule)[$injector]:
StaticInjectorError(Platform: core)[$injector]:
NullInjectorError: No provider for $injector!
我假设它来自 UpgradeComponent 中使用的注入器。但是我不确定如何将其提供给我的 spec.ts。
Angular 很好地记录了如何在应用程序中进行这项工作,但没有关于如何测试:https ://angular.io/api/upgrade/static/UpgradeComponent
还看了这里:https ://github.com/angular/angular/issues/24369 ,但是仍然不清楚如何测试。