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
Lint
  • Loading branch information
tptee committed Oct 6, 2016
1 parent 59a5364 commit 440355e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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;
});
});
3 changes: 1 addition & 2 deletions test/store-enhancer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { compose, createStore, applyMiddleware } from 'redux';
import { install, combineReducers } from 'redux-loop';

import {
LOCATION_CHANGED, PUSH, REPLACE,
GO, GO_BACK, GO_FORWARD
LOCATION_CHANGED, PUSH
} from '../src/action-types';

import createStoreWithRouter from '../src/store-enhancer';
Expand Down

0 comments on commit 440355e

Please sign in to comment.