generated from Alorel/basic-library-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(common): Add event predicate tests
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |