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

Commit fc80b64

Browse files
committed
Unsubscribe after each test to silence warnings
1 parent ef57a69 commit fc80b64

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

test/createTests.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function createSyncedHistoryAndStore(createHistory) {
77
routing: routeReducer
88
}));
99
const history = createHistory();
10-
syncReduxAndRouter(history, store);
11-
return { history, store };
10+
const unsubscribe = syncReduxAndRouter(history, store);
11+
return { history, store, unsubscribe };
1212
}
1313

1414
const defaultReset = () => {};
@@ -115,8 +115,20 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
115115
});
116116

117117
describe('syncReduxAndRouter', () => {
118+
let history, store, unsubscribe;
119+
120+
beforeEach(() => {
121+
let synced = createSyncedHistoryAndStore(createHistory);
122+
history = synced.history;
123+
store = synced.store;
124+
unsubscribe = synced.unsubscribe;
125+
});
126+
127+
afterEach(() => {
128+
unsubscribe();
129+
});
130+
118131
it('syncs router -> redux', () => {
119-
const { history, store } = createSyncedHistoryAndStore(createHistory);
120132
expect(store.getState().routing.path).toEqual('/');
121133

122134
history.pushState(null, '/foo');
@@ -147,7 +159,6 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
147159
});
148160

149161
it('syncs redux -> router', () => {
150-
const { history, store } = createSyncedHistoryAndStore(createHistory);
151162
expect(store.getState().routing).toEqual({
152163
path: '/',
153164
changeId: 1,
@@ -205,7 +216,6 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
205216
});
206217

207218
it('updates the router even if path is the same', () => {
208-
const { history, store } = createSyncedHistoryAndStore(createHistory);
209219
expect(store.getState().routing).toEqual({
210220
path: '/',
211221
changeId: 1,
@@ -239,7 +249,6 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
239249
});
240250

241251
it('does not update the router for other state changes', () => {
242-
const { history, store } = createSyncedHistoryAndStore(createHistory);
243252
store.dispatch({
244253
type: 'RANDOM_ACTION',
245254
value: 5
@@ -254,7 +263,6 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
254263
});
255264

256265
it('only updates the router once when dispatching from `listenBefore`', () => {
257-
const { history, store } = createSyncedHistoryAndStore(createHistory);
258266
expect(store.getState().routing).toEqual({
259267
path: '/',
260268
changeId: 1,
@@ -280,10 +288,9 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
280288
});
281289

282290
it('does not unnecessarily update the store', () => {
283-
const { history, store } = createSyncedHistoryAndStore(createHistory);
284291
const updates = [];
285292

286-
const unsubscribe = store.subscribe(() => {
293+
const unsubscribeFromStore = store.subscribe(() => {
287294
updates.push(store.getState())
288295
});
289296

@@ -293,7 +300,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
293300
store.dispatch(replacePath('/bar'));
294301
store.dispatch(replacePath('/bar', { bar: 'foo' }));
295302

296-
unsubscribe();
303+
unsubscribeFromStore();
297304

298305
expect(updates.length).toBe(5);
299306
expect(updates).toEqual([
@@ -341,7 +348,6 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
341348
});
342349

343350
it('allows updating the route from within `listenBefore`', () => {
344-
const { history, store } = createSyncedHistoryAndStore(createHistory);
345351
expect(store.getState().routing).toEqual({
346352
path: '/',
347353
changeId: 1,

0 commit comments

Comments
 (0)