假设我有一个带有两个输入参数的Angular 2 Component:
@Component{... (omitted for clarity)}
export class SomeComponent {
@Input() a: number
@Input() b: number
}
当我想测试这个组件时,我有类似的东西:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
SomeComponent,
],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
createComponent
调用不接受任何参数或允许我调用构造函数。如何针对各种数值实例化/测试组件?
答案 0 :(得分:1)
正如JB Nizet所指出的,当一个组件有@input参数时,你需要在beforeEach()中初始化它们: ```
TypeError: 'project' is an invalid keyword argument for Employee
```