Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Add test to confirm that other middleware can dispatch router actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tptee committed Sep 30, 2016
1 parent 3e491ea commit eb81d8e
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ import {

chai.use(sinonChai);

const REFRAGULATE = 'REFRAGULATE';

// Used to test that other middleware can dispatch
// router actions and trigger history updates
const consumerMiddleware = ({ dispatch }) => next => action => {
if (action.type === REFRAGULATE) {
dispatch({
type: PUSH,
payload: {
pathname: '/'
}
});
return;
}

next(action);
};

const init = () => {
const historyStub = {
push: sandbox.stub(),
Expand All @@ -25,7 +43,8 @@ const init = () => {
applyMiddleware(
routerMiddleware({
history: historyStub
})
}),
consumerMiddleware
)
);

Expand Down Expand Up @@ -67,4 +86,14 @@ describe('Router middleware', () => {
expect(historyStub[method]).to.not.have.been.called;
});
});

it('passes normal actions through the dispatch chain', () => {
const { store, historyStub } = init();
store.dispatch({
type: REFRAGULATE,
payload: {}
});

expect(historyStub.push).to.have.been.called.once;
});
});

0 comments on commit eb81d8e

Please sign in to comment.