From 02f2f0e1f3ce362514489fa470e5b0ab672d46f9 Mon Sep 17 00:00:00 2001
From: Angelina Filippova <linakirsanova@gmail.com>
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 42d7d3e1..5386fdc4 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
-- 
GitLab