title: Vue test-utils how to test a router.push()
body: <p>In my component , I have a method which will execute a <code>router.push()</code></p>
  
  <pre><code>import router from "@/router";
  // ...
  export default {
    // ...
    methods: {
      closeAlert: function() {
        if (this.msgTypeContactForm == "success") {
          router.push("/home");
        } else {
          return;
        }
      },
      // ....
    }
  }
  </code></pre>
  
  <p>I want to test it...</p>
  
  <p>I wrote the following specs..</p>
  
  <pre><code>it("should ... go to home page", async () =&gt; {
      // given
      const $route = {
        name: "home"
      },
      options = {
        ...
        mocks: {
          $route
        }
      };
      wrapper = mount(ContactForm, options);
      const closeBtn = wrapper.find(".v-alert__dismissible");
      closeBtn.trigger("click");
      await wrapper.vm.$nextTick();
      expect(alert.attributes().style).toBe("display: none;")
      // router path '/home' to be called ?
    });
  </code></pre>
  
  <p>1 - I get an error </p>
  
  <pre><code>console.error node_modules/@vue/test-utils/dist/vue-test-utils.js:15
  [vue-test-utils]: could not overwrite property $route, this is usually caused by a plugin that has added the property asa read-only value
  </code></pre>
  
  <p>2 - How I should write the expect() to be sure that this /home route has been called </p>
  
  <p>thanks for feedback</p>