我有一个规范代码来测试这样
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();
});
Run Code Online (Sandbox Code Playgroud)
和这样的实现代码
login() {
this.auth.login(this.username, this.password).subscribe(() => {
}
});
}
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
this.auth.login(...).subscribe不是一个函数
为什么会发生这种错误?