【发布时间】:2017-02-23 05:00:00
【问题描述】:
我已经定义了一个接口和不透明的令牌如下
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
看不到我做错了什么。有什么想法吗?
【问题讨论】: