Skip to content

Commit

Permalink
Update tests to include check for changing state
Browse files Browse the repository at this point in the history
URL stays the same, but state changes.
  • Loading branch information
Macroz committed Dec 8, 2015
1 parent 0dda517 commit 379c0ad
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
39 changes: 38 additions & 1 deletion modules/__tests__/describePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down Expand Up @@ -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)
}
]

Expand Down
31 changes: 30 additions & 1 deletion modules/__tests__/describePushState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand All @@ -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)
}
]

Expand Down

0 comments on commit 379c0ad

Please sign in to comment.