From 170079e06eded6155e8e4cea573bfd4f254ff222 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 8 Feb 2021 01:42:31 +0300 Subject: [PATCH] Replace router push with the one that catches errors --- src/router/index.js | 13 +++++++++++++ test/views/layout/index.test.js | 1 + 2 files changed, 14 insertions(+) diff --git a/src/router/index.js b/src/router/index.js index 661fb7f2..d151daeb 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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' diff --git a/test/views/layout/index.test.js b/test/views/layout/index.test.js index 686a4226..af71ee17 100644 --- a/test/views/layout/index.test.js +++ b/test/views/layout/index.test.js @@ -16,6 +16,7 @@ localVue.use(VueRouter) localVue.use(Element) jest.mock('@/api/reports') +jest.mock('@/api/settings') describe('Log out', () => { let store