From 073bb60c22b6a5e337554510ac82e93d49a8287d Mon Sep 17 00:00:00 2001 From: Justin Greenberg Date: Sat, 19 Dec 2015 13:48:29 -0500 Subject: [PATCH 1/3] chore(history): update to history ^0.14.0 internally --- examples/basic/package.json | 2 +- package.json | 2 +- src/index.js | 9 +++++--- test/createTests.js | 46 +++++++++++++++++++++---------------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/examples/basic/package.json b/examples/basic/package.json index 4f74fb8..caa3205 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -2,7 +2,7 @@ "name": "rsr-basic-example", "version": "0.0.0", "dependencies": { - "history": "^1.13.1", + "history": "^1.14.0", "react": "^0.14.2", "react-dom": "^0.14.2", "react-redux": "^4.0.0", diff --git a/package.json b/package.json index 421801f..1afd02f 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "eslint": "^1.10.3", "eslint-config-rackt": "^1.1.1", "expect": "^1.13.0", - "history": "^1.13.1", + "history": "^1.14.0", "isparta": "^4.0.0", "isparta-loader": "^2.0.0", "karma": "^0.13.3", diff --git a/src/index.js b/src/index.js index 3f4d4b6..d4a6823 100644 --- a/src/index.js +++ b/src/index.js @@ -88,7 +88,7 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST const unsubscribeHistory = history.listen(location => { const route = { path: createPath(location), - state: location.state + state: location.state === null ? undefined : location.state } if (!lastRoute) { @@ -131,8 +131,11 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST !locationsAreEqual(lastRoute, routing)) { lastRoute = routing - const method = routing.replace ? 'replaceState' : 'pushState' - history[method](routing.state, routing.path) + const method = routing.replace ? 'replace' : 'push' + history[method]({ + pathname: routing.path, + state: routing.state + }) } }) diff --git a/test/createTests.js b/test/createTests.js index 42b307d..ab568b9 100644 --- a/test/createTests.js +++ b/test/createTests.js @@ -170,7 +170,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) devToolsStore = store.devToolsStore // Set initial URL before syncing - history.pushState(null, '/foo') + history.push('/foo') unsubscribe = syncReduxAndRouter(history, store) }) @@ -185,7 +185,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) currentPath = location.pathname }) - history.pushState(null, '/bar') + history.push('/bar') store.dispatch(pushPath('/baz')) // By calling reset we expect DevTools to re-play the initial state @@ -205,9 +205,9 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) }) // DevTools action #2 - history.pushState(null, '/foo2') + history.push('/foo2') // DevTools action #3 - history.pushState(null, '/foo3') + history.push('/foo3') // When we toggle an action, the devtools will revert the action // and we therefore expect the history to update to the previous path @@ -256,49 +256,55 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) path: '/' }) - history.pushState(null, '/foo') + history.push('/foo') expect(store).toContainRoute({ path: '/foo', replace: false, - state: null + state: undefined }) - history.pushState({ bar: 'baz' }, '/foo') + history.push({ state: { bar: 'baz' }, pathname: '/foo' }) expect(store).toContainRoute({ path: '/foo', replace: true, state: { bar: 'baz' } }) - history.replaceState(null, '/bar') + history.replace('/bar') expect(store).toContainRoute({ path: '/bar', replace: true, - state: null + state: undefined }) - history.pushState(null, '/bar') + history.push('/bar') expect(store).toContainRoute({ path: '/bar', replace: true, - state: null + state: undefined }) - history.pushState(null, '/bar?query=1') + history.push('/bar?query=1') expect(store).toContainRoute({ path: '/bar?query=1', replace: false, - state: null + state: undefined }) - history.replaceState({ bar: 'baz' }, '/bar?query=1') + history.replace({ + state: { bar: 'baz' }, + pathname: '/bar?query=1' + }) expect(store).toContainRoute({ path: '/bar?query=1', replace: true, state: { bar: 'baz' } }) - history.pushState({ bar: 'baz' }, '/bar?query=1#hash=2') + history.replace({ + state: { bar: 'baz' }, + pathname: '/bar?query=1#hash=2' + }) expect(store).toContainRoute({ path: '/bar?query=1#hash=2', replace: true, @@ -455,7 +461,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) })) const history = createHistory() syncReduxAndRouter(history, store, state => state.notRouting) - history.pushState(null, '/bar') + history.push('/bar') expect(store.getState().notRouting.path).toEqual('/bar') }) @@ -466,7 +472,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) const history = createHistory() const unsubscribe = syncReduxAndRouter(history, store) - history.pushState(null, '/foo') + history.push('/foo') expect(store).toContainRoute({ path: '/foo' }) @@ -478,7 +484,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) unsubscribe() - history.pushState(null, '/foo') + history.push('/foo') expect(store).toContainRoute({ path: '/bar' }) @@ -523,7 +529,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) const store = createStore(combineReducers({ routing: routeReducer })) - const history = useBasename(createHistory)({ basename:'/foobar' }) + const history = useBasename(createHistory)({ basename: '/foobar' }) syncReduxAndRouter(history, store) store.dispatch(pushPath('/bar')) @@ -531,7 +537,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) path: '/bar' }) - history.pushState(undefined, '/baz') + history.push('/baz') expect(store).toContainRoute({ path: '/baz' }) From 43be04e445a6e2b2379d72473cd7d85862866e5e Mon Sep 17 00:00:00 2001 From: Justin Greenberg Date: Tue, 22 Dec 2015 18:31:32 -0500 Subject: [PATCH 2/3] refactor(tests): history returns state: null --- src/index.js | 2 +- test/createTests.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index d4a6823..a775a72 100644 --- a/src/index.js +++ b/src/index.js @@ -88,7 +88,7 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST const unsubscribeHistory = history.listen(location => { const route = { path: createPath(location), - state: location.state === null ? undefined : location.state + state: location.state } if (!lastRoute) { diff --git a/test/createTests.js b/test/createTests.js index ab568b9..3130141 100644 --- a/test/createTests.js +++ b/test/createTests.js @@ -253,14 +253,15 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) it('syncs router -> redux', () => { expect(store).toContainRoute({ - path: '/' + path: '/', + state: null }) history.push('/foo') expect(store).toContainRoute({ path: '/foo', replace: false, - state: undefined + state: null }) history.push({ state: { bar: 'baz' }, pathname: '/foo' }) @@ -274,21 +275,21 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) expect(store).toContainRoute({ path: '/bar', replace: true, - state: undefined + state: null }) history.push('/bar') expect(store).toContainRoute({ path: '/bar', replace: true, - state: undefined + state: null }) history.push('/bar?query=1') expect(store).toContainRoute({ path: '/bar?query=1', replace: false, - state: undefined + state: null }) history.replace({ @@ -316,7 +317,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) expect(store).toContainRoute({ path: '/', replace: false, - state: undefined + state: null }) store.dispatch(pushPath('/foo')) @@ -474,7 +475,8 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) history.push('/foo') expect(store).toContainRoute({ - path: '/foo' + path: '/foo', + state: null }) store.dispatch(pushPath('/bar')) @@ -539,7 +541,8 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) history.push('/baz') expect(store).toContainRoute({ - path: '/baz' + path: '/baz', + state: null }) }) }) From 203e77387f5a66b15c1e22585719c0a1d5f0d7c7 Mon Sep 17 00:00:00 2001 From: Justin Greenberg Date: Tue, 22 Dec 2015 19:15:34 -0500 Subject: [PATCH 3/3] feat(test): test history.push with hash gets library back up to 100% coverage --- test/createTests.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/createTests.js b/test/createTests.js index 3130141..ccc04f5 100644 --- a/test/createTests.js +++ b/test/createTests.js @@ -292,6 +292,13 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) state: null }) + history.push('/bar#baz') + expect(store).toContainRoute({ + path: '/bar#baz', + replace: false, + state: null + }) + history.replace({ state: { bar: 'baz' }, pathname: '/bar?query=1'