Skip to content

Commit

Permalink
test: resolve redirect reloads parent
Browse files Browse the repository at this point in the history
  • Loading branch information
saibotsivad committed Feb 9, 2022
1 parent 848dab9 commit c4ca202
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/resolve-redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,46 @@ test(`only one cancel happens if multiple redirects are called`, t => {

t.end()
})

test(`redirecting to a child reruns the parent resolve`, t => {
function startTest(t) {
const state = getTestState(t)
const stateRouter = state.stateRouter
t.plan(2)

let parentActivatedCount = 0

stateRouter.addState({
name: `valid`,
route: `/valid`,
template: {},
resolve(data, params, cb) {
parentActivatedCount++
if (!params.anyKey) {
return cb.redirect(`valid.valid1`, { anyKey: `yes?` })
}
t.equal(parentActivatedCount, 2, `first it redirected, then it ran again`)
setTimeout(cb, 50)
},
})

stateRouter.addState({
name: `valid.valid1`,
route: `/valid1/:anyKey`,
template: {},
activate() {
t.pass(`valid.valid1 activated`)
t.end()
},
})

return state
}

t.test(`with state.go`, t => {
const stateRouter = startTest(t).stateRouter
stateRouter.go(`valid`)
})

t.end()
})

0 comments on commit c4ca202

Please sign in to comment.