【发布时间】:2018-09-17 13:47:08
【问题描述】:
我有一个包含以下 2 种方法的组件。
如何在 ngOnInit() 上测试 nameList() 方法是否为 haveBeenCalledWith(students)
constructor(route: ActivatedRoute, location: Location) {
}
ngOnInit() {
this.route.data
subscribe((data: { students: Students }) => {
const students: Students = data.students;
this.nameList(students);
});
}
nameList(students: Student) {
.....
}
到目前为止我所拥有的:
describe('ngOnInit', () => {
it('should extract data from route', () => {
component = fixture.componentInstance;
spyOn(component.route.data, 'subscribe').and.callFake((data: { students: Students }) => { } );
component.ngOnInit();
fixture.detectChanges();
expect(component.nameList).toHaveBeenCalledWith(students);
});
});
【问题讨论】:
标签: angular typescript unit-testing jasmine karma-jasmine