Skip to content

Cannot mock the global $route and $router since vue-router update to v2.8.0 #528

@cherry200604

Description

@cherry200604

Version

1.0.0-beta.13

Reproduction link

https://jsfiddle.net/getk99n0/

Steps to reproduce

  1. Follow the tutorial (https://vue-test-utils.vuejs.org/en/guides/using-with-vue-router.html) to mock the $route

import { shallow } from '@vue/test-utils'

describe('test', () => {
  it('mock $route', () => {
    const $route = { path: '/some/path' }
    const wrapper = shallow(Sidebar, { mocks: { $route } }).vm
    console.log(wrapper.$route)
  })
})
  1. run the test and got undefined

What is expected?

Should get correct mock $route/$router value

What is actually happening?

Get undefined from wrapper.$route and wrapper.$router


I can still get { path: '/some/path' } as result when the version of the vue-router still in v2.7.0, sorry not sure if I should raise the issue here or in vue-router, can anyone help please :(? thanks!

NOTE that I also get this error '[vue-test-utils]: could not overwrite property $route, this usually caused by a plugin that has added the property as a read-only value' but I didn't use any VueRouter in my other test case includes current one.

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