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

Increase test coverage #43

Merged
merged 4 commits into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
node_modules
node_modules
coverage
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"scripts": {
"build": "mkdir -p lib && babel ./src/index.js --plugins transform-object-assign --out-file ./lib/index.js",
"test": "mocha --compilers js:babel-core/register --recursive",
"test:cov": "babel-node $(npm bin)/isparta cover $(npm bin)/_mocha -- --recursive",
"prepublish": "npm run build"
},
"tags": [
Expand All @@ -32,6 +33,7 @@
"babel-preset-es2015": "^6.1.2",
"expect": "^1.13.0",
"history": "^1.13.1",
"isparta": "^4.0.0",
"mocha": "^2.3.4",
"redux": "^3.0.4"
}
Expand Down
49 changes: 49 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,53 @@ describe('syncReduxAndRouter', () => {
changeId: 3
});
})

it('throws if "routing" key is missing with default selectRouteState', () => {
const store = createStore(combineReducers({
notRouting: routeReducer
}));
const history = createHistory();
expect(
() => syncReduxAndRouter(history, store)
).toThrow(/Cannot sync router: route state does not exist/);
});

it('accepts custom selectRouterState', () => {
const store = createStore(combineReducers({
notRouting: routeReducer
}));
const history = createHistory();
syncReduxAndRouter(history, store, state => state.notRouting)
history.pushState(null, '/bar');
expect(store.getState().notRouting.path).toEqual('/bar');
});

it('returns unsubscribe to stop listening to history and store', () => {
const store = createStore(combineReducers({
routing: routeReducer
}));
const history = createHistory();
const unsubscribe = syncReduxAndRouter(history, store)

history.pushState(null, '/foo');
expect(store.getState().routing.path).toEqual('/foo');

store.dispatch(updatePath('/bar'));
expect(store.getState().routing).toEqual({
path: '/bar',
changeId: 2
});

unsubscribe();

history.pushState(null, '/foo');
expect(store.getState().routing.path).toEqual('/bar');

history.listenBefore(location => {
throw new Error()
});
expect(
() => store.dispatch(updatePath('/foo'))
).toNotThrow();
});
});