我正在尝试测试我的Angular 4.1.0组件 -
export class CellComponent implements OnInit {
lines: Observable<Array<ILine>>;
@Input() dep: string;
@Input() embedded: boolean;
@Input() dashboard: boolean;
constructor(
public dataService: CellService,
private route: ActivatedRoute,
private router: Router, private store: Store<AppStore>) {
}
}
然而,一个简单的“should create”测试会产生以下晦涩的错误信息:
因此,我发现了这个问题,它表明组件具有未设置的NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'ng:///DynamicTestModule/module.ngfactory.js'.
@Input
参数。如果我像下面这样修改我的测试: it('should create', inject([CellComponent], (cmp: CellComponent) => {
cmp.dep = '';
cmp.embedded = false;
cmp.dashboard = false;
expect(cmp).toBeTruthy();
}));
如果我仍然遇到同样的问题,同样地,如果我从组件中删除@Input()
注释,也没有任何区别。我该如何使这些测试通过?