title: Vue.js vue-router anyway to test the navigation guards?
body: <p>Is there any way to unit test the navigation guards in a router file ?</p>
  
  <p>Could not find any post or link on this topic ... ant tips, trick or feedback welcome..</p>
  
  <p>Here is the router/index.js , and I would like to test the router.beforeEach()</p>
  
  <pre><code>    import Vue from 'vue'
      import VueRouter from 'vue-router'
      import Home from '@/pages/HomePage'
      import Login from '@/pages/LoginPage'
      import ShoppingLists from '@/pages/ShoppingListsPage'
  
      import vueAuthInstance from '../services/auth.js'
  
      Vue.use(VueRouter)
  
      const router = new VueRouter({
        mode: 'history',
        routes: [
          {
            path: '/',
            name: 'home',
            component: Home,
            meta: { auth: false, title: 'Home' }
          },
          {
            path: '/login',
            name: 'login',
            component: Login,
            meta: { auth: false, title: 'Login' }
          },
          {
            path: '/shoppinglists',
            name: 'shoppinglists',
            component: ShoppingLists,
            meta: { auth: true, title: 'Shopping Lists' }
          },
          {
            path: '/logout',
            name: 'logout'
          }
        ]
      })
  
      router.beforeEach(function (to, from, next) {
        if (to.meta &amp;&amp; to.meta.title) {
          document.title = to.meta.title
        }
        if (to.meta &amp;&amp; to.meta.auth !== undefined) {
          if (to.meta.auth) {
            if (vueAuthInstance.isAuthenticated()) {
              next()
            } else {
              router.push({ name: 'login' })
            }
          } else {
            next()
          }
        } else {
          next()
        }
      })
  
      export default router
  </code></pre>