Last active
January 28, 2017 16:21
-
-
Save lmatteis/1cdb8988808cab7c497d3caa19971a05 to your computer and use it in GitHub Desktop.
Example redux-cycle-middleware test
This file contains hidden or 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
import { createCycleMiddleware } from 'redux-cycle-middleware'; | |
import configureMockStore from 'redux-mock-store' | |
import expect from 'expect' // You can use any testing library | |
describe('Redux cycle middleware', () => { | |
it('dispatches a PING to see whether the middleware dispatches a PONG', () => { | |
function main(sources) { | |
const pong$ = sources.ACTION | |
.filter(action => action.type === 'PING') | |
.mapTo({ type: 'PONG' }); | |
return { | |
ACTION: pong$ | |
} | |
} | |
const cycleMiddleware = createCycleMiddleware(main, {}); | |
const middlewares = [ cycleMiddleware ] | |
const mockStore = configureMockStore(middlewares) | |
const expectedActions = [ | |
{ type: 'PING' }, | |
{ type: 'PONG' } | |
] | |
const store = mockStore({ todos: [] }) | |
store.dispatch({ type: 'PING' }) | |
expect(store.getActions()).toEqual(expectedActions) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment