Description
Version
1.0.0-beta.29
Reproduction link
https://github.com/nlochschmidt/vue-router-test-utils-bug
Steps to reproduce
I attempted to test the properties that are passed to a component that is created by my router. I was following the examples from the docs but didn't want to fully mount the component in question because of it's behaviour on mounting, etc.
Here are the relevant parts from the repository linked above:
router.ts
export default (localVue = Vue) => {
localVue.use(Router)
return new Router({
routes: [
{
path: '/',
name: 'home',
component: Home
}
]
})
}
Home.vue
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js TypeScript App"/>
</div>
</template>
...
router.spec.ts
describe("router", () => {
test("should show Home component on /", () => {
const localVue = createLocalVue()
const router = createRouter(localVue)
const wrapper = mount(
{ render: h => h("router-view") },
{
localVue,
router,
stubs: {
Home
}
})
expect(wrapper.find(Home).exists()).toBe(true)
expect(wrapper.find(HelloWorld).exists()).toBe(false) // <- this fails
})
})
What is expected?
Since Home
should be stubbed, the child component HelloWorld
, shouldn't get mounted and shouldn't exist when checking wrapper.find(HelloWorld).exists()
What is actually happening?
The stubs
configuration is ignored and the Home
component actually gets created and mounted.
I would also be interested in knowing how else I can check that the correct props are provided to a component without actually creating that component.