Skip to content

Mocking the router for testing (using vitest) is not working (vue-router version 4.1.x) #1503

@SimonPreini

Description

@SimonPreini

Version

4.1.3

Reproduction link

github.com

Steps to reproduce

Checkout code

git clone https://github.com/SimonPreini/VueRouterTesting

install dependencies

npm install

run tests

npm run test

What is expected?

Tests should finish successfully.

What is actually happening?

The router does not get mocked and is undefined -> test fails

[Vue warn]: injection "Symbol(router)" not found. at <ComponentToTest ref="VTU_COMPONENT" > at <VTUROOT>

[Vue warn]: Unhandled error during execution of native event handler at <ComponentToTest ref="VTU_COMPONENT" > at <VTUROOT> Error: Uncaught [TypeError: Cannot read properties of undefined (reading 'push')]


I created a mock for the router to check if it gets called. When I run the test it seems like the router is undefined and .push can not be executed which leads the test to fail.

When installing vue-router with version 4.0.x it works as expected.

Versions:

vue: 3.2.37

vue-router: 4.1.0

vitest: 0.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions