title: Testing Vue Router in component navigation guard
body: <p>I'm trying to unit test (with <code>vue-test-utils</code>) a component, which has a <code>beforeRouteUpdate</code> in component navigation Guard like this:</p>
  <pre class="lang-js prettyprint-override"><code>    &lt;template&gt;
         ...
      &lt;/template&gt;
      &lt;script&gt;
      export default {
          computed: {
              ...
          }
          ...
          beforeRouteUpdate(to, from, next) {
              // code to be tested
              this.$store.dispatch('setActiveTask')
          }
      }
      &lt;/script&gt;
  </code></pre>
  <p>I do render the component in the test file with <code>shallowMount</code> and mock stuff like the <code>$store</code>.</p>
  <pre class="lang-js prettyprint-override"><code>    beforeEach(() =&gt; {
          cmp = shallowMount(Task, {
                      mocks: {
                          $store: store,
                          $route: {
                              params: {
                                  taskID: 12,
                                  programID: 1
                              }
                          }
                      },
                      i18n: new VueI18N({
                          silentTranslationWarn: true
                      }),
                      stubs: {
                          'default-layout': EmptySlotComponent,
                          'nested-router': EmptySlotComponent,
                          RouterLink: RouterLinkStub
                      }
                  })
      })
  
      it('has beforeRouteUpdate hook', () =&gt; {
          // how do i call beforeRouteUpdate now?
          // cmp.vm.beforeRouteUpdate(...)
      }
  </code></pre>
  <p>Has anyone some ideas about this?</p>
  <p>UPDATE:
  I created a minimal example with <code>@vue/cli</code> and Mocha + Chai as unit test tools, which can be found here: <a href="https://github.com/BerniWittmann/vue-test-navigation-guard-reproduction" rel="nofollow noreferrer">https://github.com/BerniWittmann/vue-test-navigation-guard-reproduction</a></p>