Skip to content

Commit b0ef497

Browse files
committed
test: improve redirect error test
1 parent 40e4df7 commit b0ef497

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Diff for: src/history/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ export class History {
7878
onAbort?: Function
7979
) {
8080
let route
81+
// catch redirect option https://github.com/vuejs/vue-router/issues/3201
8182
try {
8283
route = this.router.match(location, this.current)
8384
} catch (e) {
8485
this.errorCbs.forEach(cb => {
8586
cb(e)
8687
})
8788
// Exception should still be thrown
88-
// https://github.com/vuejs/vue-router/issues/3201
8989
throw e
9090
}
9191
this.confirmTransition(

Diff for: test/unit/specs/error-handling.spec.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,12 @@ describe('error handling', () => {
184184
})
185185
})
186186

187-
it('should trigger onError when an exception is thrown', done => {
187+
it('should trigger onError if error is thrown inside redirect option', done => {
188+
const error = new Error('foo')
188189
const config = [{
189190
path: '/oldpath/:part',
190191
redirect: (to) => {
191-
if (to.ooopsmistake.part) {
192-
return `/newpath/${to.params.part}`
193-
}
194-
return '/newpath/'
192+
throw error
195193
}
196194
}]
197195

@@ -207,8 +205,8 @@ describe('error handling', () => {
207205
.push('/oldpath/test')
208206
.catch(pushCatch)
209207
.finally(() => {
210-
expect(pushCatch).toHaveBeenCalled()
211-
expect(onError).toHaveBeenCalled()
208+
expect(pushCatch).toHaveBeenCalledWith(error)
209+
expect(onError).toHaveBeenCalledWith(error)
212210
done()
213211
})
214212
})

0 commit comments

Comments
 (0)