Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit 4091b1e

Browse files
committed
Add tests for devtools fix
1 parent fb1508c commit 4091b1e

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"karma-webpack": "^1.7.0",
5454
"mocha": "^2.3.4",
5555
"redux": "^3.0.4",
56+
"redux-devtools": "^2.1.5",
5657
"webpack": "^1.12.9"
5758
},
5859
"dependencies": {

test/createTests.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const expect = require('expect');
22
const { pushPath, replacePath, UPDATE_PATH, routeReducer, syncReduxAndRouter } = require('../src/index');
3-
const { createStore, combineReducers } = require('redux');
3+
const { createStore, combineReducers, compose } = require('redux');
4+
const { devTools } = require('redux-devtools');
5+
const { ActionCreators } = require('redux-devtools/lib/devTools');
46

57
function createSyncedHistoryAndStore(createHistory) {
68
const store = createStore(combineReducers({
@@ -130,6 +132,77 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
130132
});
131133
});
132134

135+
describe('devtools', () => {
136+
let history, store, devToolsStore, unsubscribe;
137+
138+
beforeEach(() => {
139+
history = createHistory();
140+
const finalCreateStore = compose(devTools())(createStore);
141+
store = finalCreateStore(combineReducers({
142+
routing: routeReducer
143+
}));
144+
devToolsStore = store.devToolsStore;
145+
146+
// Set initial URL before syncing
147+
history.pushState(null, '/foo');
148+
149+
unsubscribe = syncReduxAndRouter(history, store);
150+
});
151+
152+
afterEach(() => {
153+
unsubscribe();
154+
});
155+
156+
it('resets to the initial url', () => {
157+
let lastPath;
158+
const historyUnsubscribe = history.listen(location => {
159+
lastPath = location.pathname;
160+
});
161+
162+
history.pushState(null, '/bar');
163+
store.dispatch(pushPath('/baz'));
164+
165+
devToolsStore.dispatch(ActionCreators.reset());
166+
167+
expect(store.getState().routing.path).toEqual('/foo');
168+
expect(lastPath).toEqual('/foo');
169+
});
170+
171+
it('handles toggle after store change', () => {
172+
let lastPath;
173+
const historyUnsubscribe = history.listen(location => {
174+
lastPath = location.pathname;
175+
});
176+
177+
// action 2
178+
history.pushState(null, '/foo2');
179+
// action 3
180+
history.pushState(null, '/foo3');
181+
182+
devToolsStore.dispatch(ActionCreators.toggleAction(3));
183+
expect(lastPath).toEqual('/foo2');
184+
185+
historyUnsubscribe();
186+
});
187+
188+
it('handles toggle after store change', () => {
189+
let lastPath;
190+
const historyUnsubscribe = history.listen(location => {
191+
lastPath = location.pathname;
192+
});
193+
194+
// action 2
195+
store.dispatch(pushPath('/foo2'));
196+
// action 3
197+
store.dispatch(pushPath('/foo3'));
198+
199+
devToolsStore.dispatch(ActionCreators.toggleAction(3));
200+
expect(lastPath).toEqual('/foo2');
201+
202+
historyUnsubscribe();
203+
});
204+
});
205+
133206
describe('syncReduxAndRouter', () => {
134207
let history, store, unsubscribe;
135208

0 commit comments

Comments
 (0)