我正在为AuthenticationService编写jasmine单元测试。我需要测试logout方法是否清除了用户身份验证。在这样做时,我要求:
断言用户不再经过身份验证
describe('logout', () => {
it('should clear user authentication', fakeAsync(() => {
authenticationService.login(loginContext)
.subscribe(() => {
expect(authenticationService.isAuthenticated()).toBe(true);
authenticationService.logout()
.subscribe(() => {
expect(authenticationService.isAuthenticated()).toBe(false);
expect(authenticationService.credentials).toBeNull();
expect(sessionStorage.getItem(credentialsKey)).toBeNull();
expect(localStorage.getItem(credentialsKey)).toBeNull();
});
});
const logoutRequest = httpMock.expectOne(`${environment.apiSettings.serviceUrl}${logoutApi}`);
expect(logoutRequest.request.method).toEqual('POST');
logoutRequest.flush(true);
}));
如下所示,httpMock完全不喜欢这样。我觉得在这种情况下我需要以某种方式使用flatMap,但是还没有能够让它工作。有什么想法吗?
答案 0 :(得分:0)
submit()