When I try to do:
const $route = { path: 'http://localhost/some/internal/path' }
wrapper = mount(Component, {
intercept: {
$route
}
})
expect(wrapper.vm.$route.path).to.equal($route.path)
I get error:
setting a property that has only a getter
webpack:///~/vue-test-utils/dist/vue-test-utils.js:861:0 <- index.js:71637:25
forEach@[native code]
install@webpack:///~/vue-test-utils/dist/vue-test-utils.js:860:0 <- index.js:71636:49
use@webpack:///~/vue/dist/vue.esm.js:4314:0 <- index.js:9612:27
createConstructor@webpack:///~/vue-test-utils/dist/vue-test-utils.js:916:0 <- index.js:71692:20
mount@webpack:///~/vue-test-utils/dist/vue-test-utils.js:971:0 <- index.js:71747:29
I think that $router will have been added to the base Vue instance as a read only property.
When you install Vue Router (Vue.use(VueRouter)), Vue Router adds $router and $route as read only properties.
Check to see if you're installing Vue Router anywhere in your test suite.
True, I had Vue.use(VueRouter) but in source code. It comes to tests with webpack
template for vue-cli.
I've opened an issue to make $route and $router writable - https://github.com/vuejs/vue-router/issues/1768
Most helpful comment
I've opened an issue to make
$routeand$routerwritable - https://github.com/vuejs/vue-router/issues/1768