Skip to content

Commit

Permalink
Add next handler for Observables' tests (#608)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dingyuchen authored Mar 1, 2021
1 parent d0130bf commit 91a350f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/app/core/models/session-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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)),
});
});

Expand All @@ -47,6 +47,7 @@ describe('Session Model', () => {
of({ openPhases: [] })
.pipe(assertSessionDataIntegrity())
.subscribe({
next: () => fail(),
error: (err) => expect(err).toEqual(new Error(NO_ACCESSIBLE_PHASES)),
});
});
Expand All @@ -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({
Expand Down

0 comments on commit 91a350f

Please sign in to comment.