79829571

Date: 2025-11-25 10:37:02
Score: 1.5
Natty:
Report link

You only need to stub it in the component where you're using router-link. Just ran into this warning and seems not well documented it can be solved like so:


import { mount, RouterLinkStub } from "@vue/test-utils";
import { describe, expect, it } from "vitest";
import SomeComponent from "@/components/SomeComponent.vue";

describe("SomeComponent tests", () => {
  it("Renders my component with links in it", () => {
    const some_comp = mount(SomeComponent, {
      props: {
        label: "some text",
        link: "/some/url/here",
      },

      global: {
        stubs: {
          "router-link": RouterLinkStub,
        },
      },
    });

    // it renders and we check the link is set:
    expect(some_comp.text()).toContain("some text");
    const link_component = some_comp.findComponent(RouterLinkStub);
    expect(link_component.props().to).toBe("/some/url/here");

  });
});
Reasons:
  • RegEx Blacklisted phrase (1): check the link
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Walter Schreppers