Skip to content

Commit cc2fb7e

Browse files
committed
Refactor
1 parent e078251 commit cc2fb7e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

packages/create-instance/create-component-stubs.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ function resolveOptions(component, _Vue) {
7575
return options
7676
}
7777

78+
function getScopedSlotRenderFunctions(ctx: any): Array<String> {
79+
// In Vue 2.6+ a new v-slot syntax was introduced
80+
// scopedSlots are now saved in parent._vnode.data.scopedSlots
81+
// We filter out the _normalized and $stable key
82+
if (
83+
ctx &&
84+
ctx.$options &&
85+
ctx.$options.parent._vnode &&
86+
ctx.$options.parent._vnode.data &&
87+
ctx.$options.parent._vnode.data.scopedSlots
88+
) {
89+
return Object.keys(ctx.$options.parent._vnode.data.scopedSlots).filter(
90+
x => x[0] !== '_' && !x.includes('$')
91+
)
92+
}
93+
94+
return []
95+
}
96+
7897
export function createStubFromComponent(
7998
originalComponent: Component,
8099
name: string,
@@ -93,18 +112,6 @@ export function createStubFromComponent(
93112
$_vueTestUtils_original: originalComponent,
94113
$_doNotStubChildren: true,
95114
render(h, context) {
96-
// In Vue 2.6+ a new v-slot syntax was introduced
97-
// scopedSlots are now saved in parent._vnode.data.scopedSlots
98-
// We filter out the _normalized and $stable key
99-
const renderFns =
100-
this &&
101-
this.$options &&
102-
this.$options.parent._vnode &&
103-
this.$options.parent._vnode.data &&
104-
this.$options.parent._vnode.data.scopedSlots &&
105-
Object.keys(this.$options.parent._vnode.data.scopedSlots).filter(
106-
x => x[0] !== '_' && !x.includes('$')
107-
)
108115
return h(
109116
tagName,
110117
{
@@ -124,10 +131,9 @@ export function createStubFromComponent(
124131
context
125132
? context.children
126133
: this.$options._renderChildren ||
127-
(renderFns &&
128-
renderFns.map(x =>
129-
this.$options.parent._vnode.data.scopedSlots[x]()
130-
))
134+
getScopedSlotRenderFunctions(this).map(x =>
135+
this.$options.parent._vnode.data.scopedSlots[x]()
136+
)
131137
)
132138
}
133139
}

0 commit comments

Comments
 (0)