Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Last active January 28, 2017 16:21
Show Gist options
  • Save lmatteis/1cdb8988808cab7c497d3caa19971a05 to your computer and use it in GitHub Desktop.
Save lmatteis/1cdb8988808cab7c497d3caa19971a05 to your computer and use it in GitHub Desktop.
Example redux-cycle-middleware test
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