import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Routes } from '@angular/router';
+import { Router, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
-import { configureTestBed } from '../../../testing/unit-test-helper';
+import { configureTestBed } from '~/testing/unit-test-helper';
import { AuthStorageService } from '../services/auth-storage.service';
import { AuthService } from './auth.service';
});
beforeEach(() => {
- service = TestBed.get(AuthService);
- httpTesting = TestBed.get(HttpTestingController);
+ service = TestBed.inject(AuthService);
+ httpTesting = TestBed.inject(HttpTestingController);
});
afterEach(() => {
expect(localStorage.getItem('dashboard_username')).toBe('foo');
}));
- it('should logout and remove the user', fakeAsync(() => {
+ it('should logout and remove the user', () => {
+ const router = TestBed.inject(Router);
+ spyOn(router, 'navigate').and.stub();
+
service.logout();
const req = httpTesting.expectOne('api/auth/logout');
expect(req.request.method).toBe('POST');
req.flush({ redirect_url: '#/login' });
- tick();
expect(localStorage.getItem('dashboard_username')).toBe(null);
- }));
+ expect(router.navigate).toBeCalledTimes(1);
+ });
});