Skip to content

Commit

Permalink
tests(common): Add event predicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Sep 26, 2020
1 parent 408fba9 commit d9275e8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .nycrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ all: true
include: projects/**/*.ts
exclude:
- '**/*.spec.ts'
- '**/index.ts'
- build/**/*
- test/**/*
sourceMap: true
Expand Down
50 changes: 50 additions & 0 deletions projects/core/common/events.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {expect} from 'chai';
import {isActionDispatchedEvent} from './ActionDispatchedEvent';
import {
createActionProcessedEvent,
isActionProcessedEvent,
isMutatingActionProcessedEvent
} from './ActionProcessedEvent';
import {isInitialStateEvent} from './InitialStateEvent';
import {isInitialStateRequestEvent} from './InitialStateRequestEvent';
import {isReadyEvent} from './ReadyEvent';
import {ReduxOMTEvent} from './ReduxOMTEvent';

describe('common/events', function () {
type Spec = [(v: any) => boolean, ReduxOMTEvent];
const specs: { [k: string]: Spec } = {
ActionDispatchedEvent: [isActionDispatchedEvent, ReduxOMTEvent.ACTION_DISPATCHED],
ActionProcessedEvent: [isActionProcessedEvent, ReduxOMTEvent.ACTION_PROCESSED],
InitialStateEvent: [isInitialStateEvent, ReduxOMTEvent.INITIAL_STATE],
InitialStateRequestEvent: [isInitialStateRequestEvent, ReduxOMTEvent.INITIAL_STATE_REQUEST],
ReadyEvent: [isReadyEvent, ReduxOMTEvent.READY]
};

for (const [suiteName, [predicate, event]] of Object.entries(specs)) {
describe(suiteName, () => {
it('Should return false if input is falsy', () => {
expect(predicate(null)).to.eq(false);
});

it('Should return false if type doesn\'t match', () => {
expect(predicate({type: event + 1})).to.eq(false);
});

it('Should return true if type matches', () => {
expect(predicate({type: event})).to.eq(true);
});
});
}

describe('MutatingActionProcessedEvent', () => {
it('Should skip base check if skipBaseCheck=true', () => {
expect(() => isMutatingActionProcessedEvent(null, true))
.to.throw('Cannot read property \'changedPaths\' of null');
});

it('Should return false if changedPaths is falsy', () => {
const evt = createActionProcessedEvent({type: ''}, null);
expect(isMutatingActionProcessedEvent(evt)).to.eq(false);
});
});
});

0 comments on commit d9275e8

Please sign in to comment.