-
Notifications
You must be signed in to change notification settings - Fork 668
JSX $scopedSlots support #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What is benefit for supporting JSX $scopedSlots? |
This feature would be useful for making renderless components such as outlined by Adam here: https://adamwathan.me/renderless-components-in-vuejs/ It would be helpful to test the component api. |
Hi, please can someone help me with how I can test scoped slots? Currently, my render function looks like this
In my test (with Jest), I'm trying to mount like this:
But no luck. I've also tried making default property a method and no luck there either. I believe I followed the docs properly. How do I do this? Thanks! |
I've worked around it by wrapping the component like shallowMount({
render() {
return (
<Component
scopedSlots={{
default: <p></p>
}}
/>
);
}
}) |
hi @panganibanpj I still get
Also, won't I lose direct access to the components vm? |
@kayandrae07 You should be able to call Something like this:
|
@davestaab thank you. This was what worked for me
I had to make the scoped slot parameter a function otherwise it failed for me |
So that method works until I need to mock dependencies. When I pass options to mount/shallowMount they are set on the outer component and not on the true component I'm trying to test. (Component in the above examples) Looking forward to a first class solution to this. |
@davestaab 😄 I created a helper function that sends all the options to the Component
I'm also looking for a solution and will love to contribute in my spare time. Also, do you know how I can access the values exported from a scoped slot? |
I'm able to do this:
where "hi" is bound to the slot as message inside So |
Yeah, it's what I'm also doing. But assuming I'm exposing a method from the slot-scope. How do I access it? |
@kayandrae07 I've ended up using a template based approach like in this project: Basically I make a test helper component that uses the component in question. To test methods, I use them and assert they had the desired results. Hope this helps. |
@davestaab Thank you! Taking a look at Vue-promised and its tests and I found a suitable solution to my problem. Since it uses scoped-slots too, I can just mirror their implementation. |
It seems that this example does not use scopedSlots: {
foo: (createElement, props) => { return createElement('div', props); },
}, |
I was encountering similar scoped slot testing issues when using a
|
What problem does this feature solve?
Being able to use $scopedSlots with render function (specifically for JSX usage)
It will complain that
$scopedSlots.foo is not a function
, but if you make it a function, it will say$scopedSlots.foo.trim() is not a function
What does the proposed API look like?
I prefer if
scopedSlots
can be passed function values like:Otherwise, at least make it so the above syntax would still work (with string
scopedSlot.foo
values but thethis.$scopedSlots.foo()
in the render function still work)The text was updated successfully, but these errors were encountered: