-
Notifications
You must be signed in to change notification settings - Fork 668
new slot syntax template can't be accessed in shallowMount #1261
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
Are there any workarounds (other then using the deprecated syntax)? |
Very interested in this issue, so that we can upgrade our syntax and still be able to test our components. |
What I've found is you need to provide your own stub for the component with slots. If you do that and add the named slots you care about then they will render in the shallowMount. wrapper = shallowMount(Appbar, {
store, router, localVue, vuetify, stubs: {
VTooltip: '<v-tooltip-stub><slot></slot><slot name="activator"></slot></v-tooltip-stub>',
},
}); |
@Stoom That does not help if you need to test something that is inside a higher order component that uses scoped slots. E.g. in the following example, anything inside <SomeHigherOrderComponent v-slot="scope">
<p>
We can use <code>scope</code> here,
but <code>shallowMount</code> will stub this out.
So we have to use <code>mount</code> to test it.
</p>
</SomeHigherOrderComponent> |
Perhaps this is relevant, but vuese is experiencing a similar issue of not being able to access content inside slots that use the new |
@runarberg When I was testing VHover from vuetify I just did the following and it worked enough for me.... wrapper = shallowMount(Settings, {
propsData, localVue, vuetify, store, stubs: {
VHover: `<slot></slot>`,
},
}); |
@Stoom That doesn’t work for me. What I need to test is a child of the component using the <MyParent>
<p>This is OK</p>
<template v-slot="scope">
<p>
<strong>I need to test this.</strong>
And I don’t know how to use <var>shallowMount</var>
without it stubbing this out.
</p>
</template>
</MyParent> Here |
Good slot support is something we will address before moving from beta to 1.0 - I'll try my best to fix this in the near future. |
Tried reproducing but failed to do so here: https://github.com/vuejs/vue-test-utils/pull/1383/files I'll try pulling the reproduction repo. |
Progress! I got it working in #1383 Need to clean the code up and cover some edge cases (and support dynamic slots). Hopefully get this merged in soon! |
Merged in... this will go out in beta-31. |
Why this issue has been closed? It seems issue has not been fixed, it still fails with provided link on version beta-31. Tests with new slot syntax in our production code also fails when updated to beta-31. |
I thought this had been fixed - at least, we have unit tests merged in using the new You are right - the provided repo fails. This is the source component: <template>
<Foo>
<template v-slot:newSyntax>
<p class="new-example">text not rendered</p>
</template>
<template slot="oldSyntax">
<p class="old-example">text rendered</p>
</template>
</Foo>
</template> This is the source test test("render old syntax slot", () => {
const wrapper = shallowMount(App);
expect(wrapper.find(Foo).exists()).toBe(true);
expect(wrapper.find(".old-example").exists()).toBe(true);
});
test("render new syntax slot", () => {
const wrapper = shallowMount(App);
expect(wrapper.find(Foo).exists()).toBe(true);
console.log(wrapper.html())
expect(wrapper.find(".new-example").exists()).toBe(true);
}); Removing the template with <template>
<Foo>
<template slot="oldSyntax">
<p class="old-example">text rendered</p>
</template>
</Foo>
</template>
// test
test("render old syntax slot", () => {
const wrapper = shallowMount(App);
expect(wrapper.find(Foo).exists()).toBe(true);
expect(wrapper.find(".old-example").exists()).toBe(true);
}); And the same applies for the new syntax and new syntax test. I wonder if mixing the syntaxes is messing things up? After thinking about this a bit more, does this even make sense? If we are using <template>
<Foo>
<template slot="oldSyntax">
<p class="old-example">text rendered</p>
</template>
</Foo>
</template> We are stubbing out
no? @mtwolak can you provide a simple version of your failing production test? I am assuming you do not combine the new and old syntax. |
We're using vuetify v-tooltip: https://codesandbox.io/s/stoic-cookies-ovlv0. I didn't include vuetify library in codesand because of readability. |
I played with this and no luck. It could be related to Vuetify; it looks like it uses requestAnimationFrame and transitions to handle the tooltip, which are both things we have struggled with in the jsdom environment. I'm surprised the first case with the old slot syntax works at all; that seems like a bug to me, in
<template>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<div v-on="on">
<span class="grey--text">Text to be checked</span>
</div>Some text for tooltip
</template>
</v-tooltip>
</template> In this component (you called in If you were mounting a I am trying to figure out exactly what |
I thought only things from |
The idea of You should be able to use |
It works with mount: https://codesandbox.io/s/gracious-satoshi-1zh8m. |
However it seems it's strictly related to Vuetify, some of its components does not generate inner content anyway, for instance: https://codesandbox.io/s/gracious-satoshi-1zh8m |
@mtwolak no bug, just looked it up - Vuetify's menu is closed by default. The test passes if you add a <v-menu offset-y :value="true">
<v-list>
<v-list-item key="ab">
<v-list-item-title>
<span>This text should be displayed</span>
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu> Everything should work correctly using Did you find any other problems with Vuetify and mount? |
@lmiller1990 everything works as expected. I tried with more complex templates and adding value set to true resolves all problems. Thanks for help, completely missed out property "value" - I was searching for property called "visible" or "expand" or sth like that and it turned out value was exactly what I was searching for. This issue should be closed, everything is correctly rendered. |
Version
1.0.0-beta.29
Reproduction link
https://codesandbox.io/embed/vue-template-dr6i7?fontsize=14&previewwindow=tests
Steps to reproduce
Run the two tests in the link. The one pointing to the old syntax's slot will pass, the one pointing to the new slot's syntax won't.
What is expected?
Template with v-slot syntax can be accessed in the test when using shallow mount.
What is actually happening?
The test pointing to the template using the new slot syntax fails, whereas the one with the soon-to-be deprecated syntax passes.
The text was updated successfully, but these errors were encountered: