Skip to content

Commit

Permalink
test: improve redirect error test
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 3, 2020
1 parent 40e4df7 commit b0ef497
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/history/base.js
Expand Up @@ -78,14 +78,14 @@ export class History {
onAbort?: Function
) {
let route
// catch redirect option https://github.com/vuejs/vue-router/issues/3201
try {
route = this.router.match(location, this.current)
} catch (e) {
this.errorCbs.forEach(cb => {
cb(e)
})
// Exception should still be thrown
// https://github.com/vuejs/vue-router/issues/3201
throw e
}
this.confirmTransition(
Expand Down
12 changes: 5 additions & 7 deletions test/unit/specs/error-handling.spec.js
Expand Up @@ -184,14 +184,12 @@ describe('error handling', () => {
})
})

it('should trigger onError when an exception is thrown', done => {
it('should trigger onError if error is thrown inside redirect option', done => {
const error = new Error('foo')
const config = [{
path: '/oldpath/:part',
redirect: (to) => {
if (to.ooopsmistake.part) {
return `/newpath/${to.params.part}`
}
return '/newpath/'
throw error
}
}]

Expand All @@ -207,8 +205,8 @@ describe('error handling', () => {
.push('/oldpath/test')
.catch(pushCatch)
.finally(() => {
expect(pushCatch).toHaveBeenCalled()
expect(onError).toHaveBeenCalled()
expect(pushCatch).toHaveBeenCalledWith(error)
expect(onError).toHaveBeenCalledWith(error)
done()
})
})
Expand Down

0 comments on commit b0ef497

Please sign in to comment.