Replace router push with the one that catches errors

This commit is contained in:
Angelina Filippova 2021-02-08 01:42:31 +03:00
parent 56c20277a4
commit 170079e06e
2 changed files with 14 additions and 0 deletions

View file

@ -3,6 +3,19 @@ import Router from 'vue-router'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) { return originalPush.call(this, location, onResolve, onReject) }
return originalPush.call(this, location).catch((err) => {
if (Router.isNavigationFailure(err)) {
// resolve err
return err
}
// rethrow error
return Promise.reject(err)
})
}
/* Layout */
import Layout from '@/views/layout/Layout'

View file

@ -16,6 +16,7 @@ localVue.use(VueRouter)
localVue.use(Element)
jest.mock('@/api/reports')
jest.mock('@/api/settings')
describe('Log out', () => {
let store