我有一个规范的代码来测试像这样angular2使用茉莉的订阅方法
it('login test',() => {
const fixture = TestBed.createComponent(component);
fixture.detectChanges();
let authService = fixture.debugElement.injector.get(Auth);
spyOn(authService, 'login').and.returnValue('');
const elements = fixture.nativeElement;
fixture.componentInstance.login();
expect(authService.login).toHaveBeenCalled();
});
和实现这样的代码
login() {
this.auth.login(this.username, this.password).subscribe(() => {
}
});
}
提示错误测试:
this.auth.login(...).subscribe is not a function
为什么会发生这种错误?
适合我!谢谢 –
对于第一种选择,是否有任何方法返回值?像这样的例子:and.returnValue({subscribe:()=> {count:1000}}); – abyrne85