Comments (10)
FYI, as a workaround, this seems to work:
mount(MessageList, {
slots: {
default: {
render(h) {
return h(Message, { props: { message: 'hey' } })
}
}
}
})
from vue-test-utils.
Oh snap, I just figured it out how to do it properly. Try this.
const localVue = createLocalVue()
localVue.component('child', Child)
const wrapper = mount(Parent, {
slots: {
default: `
<child foo="bar"><div>Lorem ipsum</div></child>
<child foo="qux"><div>Dolor sit amet</div></child>
`
},
localVue
})
localVue was there for the whole time but I kept trying to mount slots with createElement
. Damn.
from vue-test-utils.
Hmm this doesn't seen to work for me. The component is created, but the props are undefined
when I try to access them...
const table = mount(TableComponent, {
propsData: {
data: [
{ firstName: 'John', lastName: 'Lennon' },
{ firstName: 'Paul', lastName: 'McCartney' },
{ firstName: 'George', lastName: 'Harrison' },
{ firstName: 'Ringo', lastName: 'Starr' },
],
},
slots: {
default: {
render(h) {
return h(TableColumn, {
props: {
show: 'firstName',
label: 'First name',
},
});
},
},
},
});
console.log(table.vm.$slots.default[0].componentInstance.show);
from vue-test-utils.
try this:
const tableCol = table.find(TableColumn)
expect(tableCol.vm.show).toBe('firstName')
expect(tableCol.vm.label).toBe('First name')
from vue-test-utils.
If anyone is looking for a workaround, try testing with another Component
let App = Vue.extend({
render (h) {
return h(Parent, {
props: {
// parent props
}
}, [
// slots
h(Child, {
props: {
// child props
}
})
])
}
})
it('has a button', () => {
let wrapper = mount(App)
console.log(wrapper.find(Parent).vm.$slots.default)
})
from vue-test-utils.
There isn't currently a way to pass mounted components to slots.
There's some work being done in avoriaz to add the option to pass Wrappers as slots. But right now there's an unsolved bug - eddyerburgh/avoriaz#113.
I'd like to add this functionality, but don't have time to work on this feature right now. I'd welcome a PR and could give you some guidance if you were willing to make one.
from vue-test-utils.
Thanks, right now I also don't have the time, but probably in the coming days I can get some and lend a hand in there. I'll contact you for that guidance in that case ;).
from vue-test-utils.
We aren't going to implement this at the moment. You can pass a component, but not an instance.
from vue-test-utils.
@eddyerburgh Is this functionality anywhere on the roadmap? I have some functionality that can't really be tested without access to instance properties, and workarounds don't always work well.
from vue-test-utils.
It's not on the roadmap. I would review a PR if somebody wants to add it.
from vue-test-utils.
Related Issues (20)
- testing a child component inside a parent slot
- Composables are not being mocked in Vitest HOT 10
- When setProps() is called on a wrapper which renders a slot, the slot's content element gets destroyed
- `RouterLink.useLink` is missing when using `RouterLinkStub`. HOT 3
- Test child component, which is the root element HOT 3
- Computed value does not update when data updates
- isVisible() not seeing display: none using vitest with jsdom HOT 4
- Testing component with onBeforeRouteLeave hook raising "No active route record was found" warning HOT 1
- vue2 引入 element2. 页面存在table 表格 jest 测试报错 HOT 1
- *.svg?inline issues
- Errors in `setup()` are silent if `render()` throws an error HOT 6
- Check style changes on hover HOT 1
- setData on writable computed property does not seem to work as it does in VTU.1
- classes documentation
- Support Vue 2.7.16 HOT 2
- Vue test utils not updating template when testing composables
- TypeError: $setup.mergeProps is not a function
- Data property is already defined in Props. HOT 1
- Unable to use vitest spy within vue/nuxt 3 component methods.
- `findComponent` doesn't find anything when using `@vue/compat` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-test-utils.