From 91a350ff518bf6da7245f6402db734fb59da9463 Mon Sep 17 00:00:00 2001 From: Ding YuChen Date: Tue, 2 Mar 2021 00:39:02 +0800 Subject: [PATCH] Add next handler for Observables' tests (#608) Some tests do not supply a 'next' callback, when subscribing to Observables that are expected to throw errors. This would cause the test to pass if no error is thrown. Let's add next handlers where appropriate so that tests fail when there is undesired behaviour. --- tests/app/core/models/session-model.spec.ts | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/app/core/models/session-model.spec.ts b/tests/app/core/models/session-model.spec.ts index fe9f3bdaa..b15d73d4b 100644 --- a/tests/app/core/models/session-model.spec.ts +++ b/tests/app/core/models/session-model.spec.ts @@ -5,7 +5,7 @@ import { OPENED_PHASE_REPO_UNDEFINED, SessionData, SESSION_DATA_UNAVAILABLE, - SESSION_DATA_MISSING_OPENPHASES_KEY + SESSION_DATA_MISSING_OPENPHASES_KEY, } from '../../../../src/app/core/models/session.model'; import { Phase } from '../../../../src/app/core/models/phase.model'; import { of } from 'rxjs'; @@ -29,8 +29,8 @@ describe('Session Model', () => { of(undefined) .pipe(assertSessionDataIntegrity()) .subscribe({ - error: (err) => - expect(err).toEqual(new Error(SESSION_DATA_UNAVAILABLE)), + next: () => fail(), + error: (err) => expect(err).toEqual(new Error(SESSION_DATA_UNAVAILABLE)), }); }); @@ -47,6 +47,7 @@ describe('Session Model', () => { of({ openPhases: [] }) .pipe(assertSessionDataIntegrity()) .subscribe({ + next: () => fail(), error: (err) => expect(err).toEqual(new Error(NO_ACCESSIBLE_PHASES)), }); }); @@ -61,29 +62,38 @@ describe('Session Model', () => { }); it('should throw error on session data with undefined repo for open phase', () => { - const modifiedSessionData: SessionData = { ...validSessionData, openPhases: [Phase.phaseBugReporting] }; + const modifiedSessionData: SessionData = { + ...validSessionData, + openPhases: [Phase.phaseBugReporting], + }; of({ ...modifiedSessionData, phaseBugReporting: undefined }) .pipe(assertSessionDataIntegrity()) .subscribe({ next: () => fail(), - error: (err) => expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), + error: (err) => + expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), }); of({ ...modifiedSessionData, phaseBugReporting: null }) .pipe(assertSessionDataIntegrity()) .subscribe({ next: () => fail(), - error: (err) => expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), + error: (err) => + expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), }); of({ ...modifiedSessionData, phaseBugReporting: '' }) .pipe(assertSessionDataIntegrity()) .subscribe({ next: () => fail(), - error: (err) => expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), + error: (err) => + expect(err).toEqual(new Error(OPENED_PHASE_REPO_UNDEFINED)), }); }); it('should not throw error if session data contains repo information of unopened phases', () => { - const modifiedSessionData: SessionData = { ...validSessionData, openPhases: [Phase.phaseBugReporting] }; + const modifiedSessionData: SessionData = { + ...validSessionData, + openPhases: [Phase.phaseBugReporting], + }; of({ ...modifiedSessionData }) .pipe(assertSessionDataIntegrity()) .subscribe({