-
Notifications
You must be signed in to change notification settings - Fork 668
v-slot not rendering along side default slot. #1868
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
It's little hard to understand. I really couldn't see |
https://github.com/rikbrowning/test-utils-slot-bug In this repository both snapshots should be the same. The only thing that is different is the slot syntax which is causing a break in snapshots. |
Check out my PR What actually happened?
<TestComponent :msg="msg" slot="test">
<div>
default slot of test component
</div>
</TestComponent>
<div>
default slot of fake component
</div> In the <template v-slot:test>
<TestComponent :msg="msg">
<div>
default slot of test component
</div>
</TestComponent>
</template>
<div>
default slot of fake component
</div> Move it under the last Also I'll recommend you to read the docs about slots again because the default content of the slot sets up directly inside the slot. |
Hey I read the docs and found this example (taken from https://vuejs.org/v2/guide/components-slots.html) <base-layout>
<template v-slot:header>
<h1>Here might be a page title</h1>
</template>
<p>A paragraph for the main content.</p>
<p>And another one.</p>
<template v-slot:footer>
<p>Here's some contact info</p>
</template>
</base-layout> The code changes you have made would put my default content inside the test slot, which is not what I want. The issue being that semantically both Working and Broken are the same but yet result in different snapshots. |
<template>
<FakeComponent>
<template v-slot:test>
<TestComponent :msg="msg">
<div>
default slot of test component
</div>
</TestComponent>
</template>
<template v-slot:default>
<div>
default slot of fake component
</div>
</template>
</FakeComponent>
</template> What about to manually set the template that falls down into the default slot of the |
I did some more investigating. The change you suggested did work for Broken.vue. However when I add a root level div the slots stop rendering again. I have updated the repo with the new Broken.vue, if you run the unit test you will see that the snapshot no longer renders out the slots. |
I read through this and have some questions. Is this bug only snapshots? I'd say a shallow mount + snapshot bug is not that big a deal - realistically, these tests are very brittle and fairly useless when it comes to actually verifying your product is working correctly. If there's a bug relating to actual slots and the |
I am also not able to |
Did some further digging. Issue seems to be in I noticed the following comment: // In Vue 2.6+ a new v-slot syntax was introduced
// scopedSlots are now saved in parent._vnode.data.scopedSlots I presume there is good reason for this change but I found that using |
Stubs are super messy - if you found a fix, make it and create a PR and see if CI fails :) I can't really remember what each and every line does there, but there should be tests around it all. |
@lmiller1990 hey I have submitted a PR but seems to be failing on the CI even though the only thing added was tests. Any idea how to fix that? |
Just took a look: https://app.circleci.com/pipelines/github/vuejs/vue-test-utils/570/workflows/29f090d2-6a16-4bcc-993d-63e09c4559d2/jobs/16342 Can you try running I am surprised your fix doesn't break things. Anyway, try fixing the linting and pushing again, see what happens. Thanks! |
Can you push what you have? I can't see that error in CI. I can take a look, need more context to provide guidance. Where are you doing that import? It should work like that - we have that same line in many places. 🤔 |
Hey, pushed my latest changes to https://github.com/rikbrowning/vue-test-utils |
Any news on this issue? I've started removing all the old deprecated slot syntax from our app & a bunch of tests are failing. Some tests kind of work, if you explicitly set a The most simple example I have is: <my-button>
<template v-slot="prepend">
<span>Hello</span>
</template>
<div>World!</div>
</my-button> What I receive: <my-button-stub>
<div>World!</div>
</my-button-stub> What I expect: <my-button-stub>
<span>Hello</span>
<div>World!</div>
</my-button-stub> |
Could you try building https://github.com/vuejs/vue-test-utils/pull/1877/files locally and see if it solves your problem? Sorry for the lack of activity here ... I have mostly been focused on VTU next, for Vue 3. I am also really hesitant to make major changes to the slots part of the code base, although we have decent test coverage, every time we change that part of the code base, it breaks a bunch of people's test suites. If you can confirm this works, we could probably run the branch against some large OSS code bases and see if it breaks anything (namely GitLab, they have a huge suite using VTU). |
So I tried to quick route & just added the changes in the PR to our project's The first issue is And then secondly, even when removing this condition for testing, the proposed change doesn't work. I checked out the proposed PR to see if I could make the tests fail & I can! 😄 By adding a default slot & some content, the named slot no longer renders. However, explicitly setting a default slot by name, correctly passes all slots (which is what I had seen above ☝️ ). You can see my fork here with the failing test when passing a default slot: https://github.com/andrewbrennanfr/vue-test-utils/commit/3c30a68e587a1abd0a101b77248917014fc0036b And also with the default slot being explicitly named, the test above ☝️ no longer fails: Edit: I think the proposed fix works to make named slots render correctly. But when paired with default slots, they are still omitted. |
Something like this: https://github.com/andrewbrennanfr/vue-test-utils/commit/e03cb4c4786f73583609f6a87b126553fa53824f fixes the issue for me (also including the proposed changes from @rikbrowning ) Although I'm completely unsure of the impact of this change. 😅 But all tests are green, and the two broken use cases for me look to be fixed too. |
Apparently this is the intended behavior in vue though 🤷♂️ https://vuejs.org/v2/guide/components-slots.html#Abbreviated-Syntax-for-Lone-Default-Slots
|
@andrewbrennanfr those repo links you posted 404 for me now. I'm hitting this same issue and I'd love to see how you fixed it! |
I think this falls into #1564 (comment) @lmiller1990 , right? |
Yeah, I'd say so - anything around shallowMount and stubs is pretty risky/messy to change at this point. If there's a quick/easy fix, that'd be fine. I won't be able to work on this right now, though. |
I'm new on wrapper = mount(TestedComponent, {
attachToDocument: true,
stubs: {
InnerComponent: mockSlots([['slotName', '']]),
},
}); And this the function mockSlots(scopedSlots) {
return {
render(h) {
return h(
'div',
scopedSlots.map(([name, slotProps]) => this.$scopedSlots[name](slotProps))
);
},
};
} If someone could validate it or even improve that would be great :) |
Subject of the issue
I recently switched a project from the old slot syntax to the new v-slot syntax and my snapshot started failing. Some of the slots are not getting rendered at all.
Steps to reproduce
I have a simplified example that showcases the issue.
My component is as follows:
It is populating the test and default slot FakeComponent. According to the vue2 docs you can but do not have to specify the default slot in a template.
My test is as follows:
Expected behaviour
I would expect the test slot to be rendered in the snap shot as it is with the old syntax.
NOTE: to get the result above I simply changed the component to this:
Actual behaviour
The text was updated successfully, but these errors were encountered: