Skip to content

Provide a way to disable warnings for "No match found" when testing  #359

Closed
@cexbrayat

Description

@cexbrayat

What problem does this feature solve?

When adding tests to a component using the router, one might need to provide a mock router. I currently use:

const mockRouter = createRouter({ history: createWebHistory(), routes: [] });
describe('Navbar.vue', () => {
  test('should ...', () => {
    const navbar = mount(Navbar, {
      global: {
        plugins: [mockRouter],
        stubs: {
          RouterLink: RouterLinkStub
        }
      }
    });
    // ...
  });
});

It works perfectly, but the router emits a warning:

console.warn node_modules/vue-router/dist/vue-router.cjs.js:225
    [Vue Router warn]: No match found for location with path "/"

As most tests are using the same code, the warning is emitted a lot and pollutes the test output.

What does the proposed API look like?

Until VTU or the router itself provides built-in support for testing (if ever, see vuejs/test-utils#152 for curious readers), do you think we could guard this warning with a setting to hide it? I can open a PR if you provide some guidance (and think this is useful of course).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionThis problem still needs more feedbackhas PRThis issue has already a PR with pending reviews

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions