87968: Fix unit tests

This commit is contained in:
Yura Bondarenko
2022-03-16 15:53:39 +01:00
parent 563956c5df
commit d78019cd39
2 changed files with 19 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { fakeAsync, flush, TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Store, StoreModule } from '@ngrx/store';
@@ -396,44 +396,43 @@ describe('AuthEffects', () => {
});
describe('when auth loaded is false', () => {
it('should not call removeToken method', (done) => {
it('should not call removeToken method', fakeAsync(() => {
store.overrideSelector(isAuthenticatedLoaded, false);
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
spyOn(authServiceStub, 'removeToken');
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
expect(authServiceStub.removeToken).not.toHaveBeenCalled();
expect(false).toBeTrue(); // subscribe to trigger taps, fail if the effect emits (we don't expect it to)
});
done();
});
tick(1000);
expect(authServiceStub.removeToken).not.toHaveBeenCalled();
}));
});
describe('when auth loaded is true', () => {
it('should call removeToken method', fakeAsync(() => {
it('should call removeToken method', (done) => {
spyOn(console, 'log').and.callThrough();
store.overrideSelector(isAuthenticatedLoaded, true);
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
spyOn(authServiceStub, 'removeToken');
authEffects.clearInvalidTokenOnRehydrate$.subscribe(() => {
expect(authServiceStub.removeToken).toHaveBeenCalled();
flush();
done();
});
}));
});
});
});
describe('invalidateAuthorizationsRequestCache$', () => {
it('should call invalidateAuthorizationsRequestCache method in response to a REHYDRATE action', (done) => {
actions = hot('--a-|', { a: { type: StoreActionTypes.REHYDRATE } });
actions = observableOf({ type: StoreActionTypes.REHYDRATE });
authEffects.invalidateAuthorizationsRequestCache$.subscribe(() => {
expect((authEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled();
done();
});
done();
});
});
});

View File

@@ -25,9 +25,11 @@ describe('Notifications reducer', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [NotificationComponent, NotificationsBoardComponent],
providers: [NotificationsService],
imports: [
providers: [
NotificationsService,
ChangeDetectorRef,
],
imports: [
StoreModule.forRoot({ notificationsReducer }, storeModuleConfig),
]
});