我定义了以下接口和不透明令牌
export let AUTH_SERVICE = new OpaqueToken('auth.service');
export interface AuthService {
logIn(): void;
logOut(): void;
}
在我的测试类中,我提供了 AuthService
的存根版本,即:@Injectable()
class AuthServiceStub implements AuthService {
logIn(): void {}
logOut(): void {}
}
然后我按照以下方式设置我的测试beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
providers: [
{provide: AUTH_SERVICE, useValue: AuthServiceStub}
]
});
}));
我随后开始撰写测试,即:it('should call log in on AuthService', () => {
let authService = fixture.debugElement.injector.get(AUTH_SERVICE);
spyOn(authService, 'logIn');
// expect will go here
});
但我收到以下错误信息
Error: <spyOn> : logIn() method does not exist
我不知道我做错了什么,请问有什么建议吗?