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

Commit 40c57bb

Browse files
committed
Merge pull request #43 from ellbee/increase_test_coverage
Increase test coverage
2 parents bd332dc + 0b5bbae commit 40c57bb

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
lib
2-
node_modules
2+
node_modules
3+
coverage

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"scripts": {
1515
"build": "mkdir -p lib && babel ./src/index.js --plugins transform-object-assign --out-file ./lib/index.js",
1616
"test": "mocha --compilers js:babel-core/register --recursive",
17+
"test:cov": "babel-node $(npm bin)/isparta cover $(npm bin)/_mocha -- --recursive",
1718
"prepublish": "npm run build"
1819
},
1920
"tags": [
@@ -32,6 +33,7 @@
3233
"babel-preset-es2015": "^6.1.2",
3334
"expect": "^1.13.0",
3435
"history": "^1.13.1",
36+
"isparta": "^4.0.0",
3537
"mocha": "^2.3.4",
3638
"redux": "^3.0.4"
3739
}

test/index.js

+49
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,53 @@ describe('syncReduxAndRouter', () => {
184184
changeId: 3
185185
});
186186
})
187+
188+
it('throws if "routing" key is missing with default selectRouteState', () => {
189+
const store = createStore(combineReducers({
190+
notRouting: routeReducer
191+
}));
192+
const history = createHistory();
193+
expect(
194+
() => syncReduxAndRouter(history, store)
195+
).toThrow(/Cannot sync router: route state does not exist/);
196+
});
197+
198+
it('accepts custom selectRouterState', () => {
199+
const store = createStore(combineReducers({
200+
notRouting: routeReducer
201+
}));
202+
const history = createHistory();
203+
syncReduxAndRouter(history, store, state => state.notRouting)
204+
history.pushState(null, '/bar');
205+
expect(store.getState().notRouting.path).toEqual('/bar');
206+
});
207+
208+
it('returns unsubscribe to stop listening to history and store', () => {
209+
const store = createStore(combineReducers({
210+
routing: routeReducer
211+
}));
212+
const history = createHistory();
213+
const unsubscribe = syncReduxAndRouter(history, store)
214+
215+
history.pushState(null, '/foo');
216+
expect(store.getState().routing.path).toEqual('/foo');
217+
218+
store.dispatch(updatePath('/bar'));
219+
expect(store.getState().routing).toEqual({
220+
path: '/bar',
221+
changeId: 2
222+
});
223+
224+
unsubscribe();
225+
226+
history.pushState(null, '/foo');
227+
expect(store.getState().routing.path).toEqual('/bar');
228+
229+
history.listenBefore(location => {
230+
throw new Error()
231+
});
232+
expect(
233+
() => store.dispatch(updatePath('/foo'))
234+
).toNotThrow();
235+
});
187236
});

0 commit comments

Comments
 (0)