diff --git a/modules/__tests__/describePush.js b/modules/__tests__/describePush.js index 7dfb6bfa8..c447ceacd 100644 --- a/modules/__tests__/describePush.js +++ b/modules/__tests__/describePush.js @@ -94,6 +94,43 @@ function describePush(createHistory) { }) it('becomes a REPLACE if path is unchanged', function (done) { + let steps = [ + function (location) { + expect(location.pathname).toEqual('/') + expect(location.search).toEqual('') + expect(location.state).toEqual(null) + expect(location.action).toEqual(POP) + + history.push({ + pathname: '/home', + search: '?the=query', + state: { the: 'state' } + }) + }, + function (location) { + expect(location.pathname).toEqual('/home') + expect(location.search).toEqual('?the=query') + expect(location.state).toEqual({ the: 'state' }) + expect(location.action).toEqual(PUSH) + + history.push({ + pathname: '/home', + search: '?the=query', + state: { the: 'state' } + }) + }, + function (location) { + expect(location.pathname).toEqual('/home') + expect(location.search).toEqual('?the=query') + expect(location.state).toEqual({ the: 'state' }) + expect(location.action).toEqual(REPLACE) + } + ] + + unlisten = history.listen(execSteps(steps, done)) + }) + + it('stays PUSH if state is changed', function (done) { let steps = [ function (location) { expect(location.pathname).toEqual('/') @@ -123,7 +160,7 @@ function describePush(createHistory) { expect(location.pathname).toEqual('/home') expect(location.search).toEqual('?the=query') expect(location.state).toEqual({ different: 'state' }) - expect(location.action).toEqual(REPLACE) + expect(location.action).toEqual(PUSH) } ] diff --git a/modules/__tests__/describePushState.js b/modules/__tests__/describePushState.js index 99b15973c..4beb4571d 100644 --- a/modules/__tests__/describePushState.js +++ b/modules/__tests__/describePushState.js @@ -36,6 +36,35 @@ function describePushState(createHistory) { }) it('becomes a REPLACE if path is unchanged', function (done) { + let steps = [ + function (location) { + expect(location.pathname).toEqual('/') + expect(location.search).toEqual('') + expect(location.state).toEqual(null) + expect(location.action).toEqual(POP) + + history.pushState({ the: 'state' }, '/home?the=query') + }, + function (location) { + expect(location.pathname).toEqual('/home') + expect(location.search).toEqual('?the=query') + expect(location.state).toEqual({ the: 'state' }) + expect(location.action).toEqual(PUSH) + + history.pushState({ the: 'state' }, '/home?the=query') + }, + function (location) { + expect(location.pathname).toEqual('/home') + expect(location.search).toEqual('?the=query') + expect(location.state).toEqual({ the: 'state' }) + expect(location.action).toEqual(REPLACE) + } + ] + + unlisten = history.listen(execSteps(steps, done)) + }) + + it('stays PUSH if state is changed', function (done) { let steps = [ function (location) { expect(location.pathname).toEqual('/') @@ -57,7 +86,7 @@ function describePushState(createHistory) { expect(location.pathname).toEqual('/home') expect(location.search).toEqual('?the=query') expect(location.state).toEqual({ different: 'state' }) - expect(location.action).toEqual(REPLACE) + expect(location.action).toEqual(PUSH) } ] diff --git a/modules/createHistory.js b/modules/createHistory.js index c29835610..7b52a762d 100644 --- a/modules/createHistory.js +++ b/modules/createHistory.js @@ -121,7 +121,7 @@ function createHistory(options={}) { const prevPath = createPath(location) const nextPath = createPath(nextLocation) - if (nextPath === prevPath) + if (nextPath === prevPath && deepEqual(location.state, nextLocation.state)) nextLocation.action = REPLACE }