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 5ca76701c2
commit 6722a9e34a
2 changed files with 14 additions and 0 deletions

View file

@ -3,6 +3,19 @@ import Router from 'vue-router'
Vue.use(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 */ /* Layout */
import Layout from '@/views/layout/Layout' import Layout from '@/views/layout/Layout'

View file

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