Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: handle shallowMount on components with v-if and scoped slots (#1663
)
  • Loading branch information
xanf committed Aug 29, 2020
1 parent f78f817 commit 41f2b2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/create-instance/create-component-stubs.js
Expand Up @@ -95,7 +95,7 @@ function resolveOptions(component, _Vue) {
function getScopedSlotRenderFunctions(ctx: any): Array<string> {
// In Vue 2.6+ a new v-slot syntax was introduced
// scopedSlots are now saved in parent._vnode.data.scopedSlots
// We filter out the _normalized and $stable key
// We filter out _normalized, $stable and $key keys
if (
ctx &&
ctx.$options &&
Expand All @@ -105,7 +105,9 @@ function getScopedSlotRenderFunctions(ctx: any): Array<string> {
ctx.$options.parent._vnode.data.scopedSlots
) {
const slotKeys: Array<string> = ctx.$options.parent._vnode.data.scopedSlots
return keys(slotKeys).filter(x => x !== '_normalized' && x !== '$stable')
return keys(slotKeys).filter(
x => x !== '_normalized' && x !== '$stable' && x !== '$key'
)
}

return []
Expand Down
24 changes: 24 additions & 0 deletions test/specs/shallow-mount.spec.js
Expand Up @@ -150,6 +150,30 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
)
})

it('renders named slots when they are located inside component with v-if', () => {
const localVue = createLocalVue()
localVue.component('Foo', {
template: '<div><slot name="newSyntax" /></div>'
})
const TestComponent = {
template: `
<Foo v-if="true">
<template v-slot:newSyntax>
<p class="new-example">text</p>
</template>
</Foo>
`
}
const wrapper = shallowMount(TestComponent, {
localVue
})
expect(wrapper.find({ name: 'Foo' }).exists()).toEqual(true)
expect(wrapper.find('.new-example').exists()).toEqual(true)
expect(wrapper.html()).toEqual(
'<foo-stub>\n' + ' <p class="new-example">text</p>\n' + '</foo-stub>'
)
})

it('renders no children if none supplied', () => {
const TestComponent = {
template: '<child />',
Expand Down

0 comments on commit 41f2b2b

Please sign in to comment.