Я хочу убедиться, что this.isLoggedIn установлен путем вызова retrieveToken.
Я также хотел бы шпионить за this.authService.currentToken
, возможно ли это или есть другой способ проверить, что наблюдаемые подписаны?
компонент
public retrieveToken(): void {
this.authService.currentToken
.subscribe(status => {
if (status) {
this.isLoggedIn = true;
}
});
}
сервис
export class AuthenticationService {
public currentTokenSubject: BehaviorSubject<any>;
public currentToken: Observable<any>;
constructor(private http: HttpClient) {
this.currentTokenSubject = new BehaviorSubject<any> ());
this.currentToken = this.currentTokenSubject.asObservable();
}
}
спецификация
it('', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
const tokenSpy = spyOn(authService, 'currenToken').and.returnValue(of({}));
app.retrieveToken();
expect(tokenSpy).toHaveBeenCalled();
});
сообщение об ошибке
Ошибка:: метод currenToken () не существует. Использование: spyOn (,)