Skip to content

Commit ad954f8

Browse files
committed
add test for localVue
1 parent 995a57d commit ad954f8

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

Diff for: packages/create-instance/create-functional-component.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { createSlotVNodes } from './create-slot-vnodes'
66

77
export default function createFunctionalComponent (
88
component: Component,
9-
mountingOptions: Options
9+
mountingOptions: Options,
10+
_Vue: Component
1011
): Component {
1112
if (mountingOptions.context && typeof mountingOptions.context !== 'object') {
1213
throwError('mount.context must be an object')
@@ -25,7 +26,7 @@ export default function createFunctionalComponent (
2526
mountingOptions.context.children.map(
2627
x => (typeof x === 'function' ? x(h) : x)
2728
)) ||
28-
createSlotVNodes(h, mountingOptions.slots || {})
29+
createSlotVNodes(h, mountingOptions.slots || {}, _Vue)
2930
)
3031
},
3132
name: component.name,

Diff for: packages/create-instance/create-instance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function createInstance (
4040
(component.options && component.options.functional) ||
4141
component.functional
4242
) {
43-
component = createFunctionalComponent(component, options)
43+
component = createFunctionalComponent(component, options, _Vue)
4444
} else if (options.context) {
4545
throwError(
4646
`mount.context can only be used when mounting a ` + `functional component`
@@ -129,7 +129,7 @@ export default function createInstance (
129129
provide: options.provide,
130130
render (h) {
131131
const slots = options.slots
132-
? createSlotVNodes(h, options.slots)
132+
? createSlotVNodes(h, options.slots, _Vue)
133133
: undefined
134134
return h(
135135
Constructor,

Diff for: packages/create-instance/create-slot-vnodes.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function startsWithTag (str: SlotValue): boolean {
1010
function createVNodesForSlot (
1111
h: Function,
1212
slotValue: SlotValue,
13-
name: string
13+
name: string,
14+
_Vue: any
1415
): VNode | string {
1516
if (typeof slotValue === 'string' && !startsWithTag(slotValue)) {
1617
return slotValue
@@ -22,6 +23,12 @@ function createVNodesForSlot (
2223
let vnode = h(el)
2324
if (typeof slotValue === 'string') {
2425
const vue = new Vue()
26+
const _vue = new _Vue()
27+
for (const key in _vue._renderProxy) {
28+
if (!(vue._renderProxy[key])) {
29+
vue._renderProxy[key] = _vue._renderProxy[key]
30+
}
31+
}
2532
try {
2633
// $FlowIgnore
2734
vnode = el.render.call(vue._renderProxy, h)
@@ -36,15 +43,18 @@ function createVNodesForSlot (
3643

3744
export function createSlotVNodes (
3845
h: Function,
39-
slots: SlotsObject
46+
slots: SlotsObject,
47+
_Vue: any
4048
): Array<VNode | string> {
4149
return Object.keys(slots).reduce((acc, key) => {
4250
const content = slots[key]
4351
if (Array.isArray(content)) {
44-
const nodes = content.map(slotDef => createVNodesForSlot(h, slotDef, key))
52+
const nodes = content.map(
53+
slotDef => createVNodesForSlot(h, slotDef, key, _Vue)
54+
)
4555
return acc.concat(nodes)
4656
}
4757

48-
return acc.concat(createVNodesForSlot(h, content, key))
58+
return acc.concat(createVNodesForSlot(h, content, key, _Vue))
4959
}, [])
5060
}

Diff for: test/specs/mounting-options/slots.spec.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
55
import ComponentWithParentName from '~resources/components/component-with-parent-name.vue'
66
import { describeWithMountingMethods, vueVersion } from '~resources/utils'
77
import { itSkipIf, itDoNotRunIf } from 'conditional-specs'
8-
import { mount } from '~vue/test-utils'
8+
import { mount, createLocalVue } from '~vue/test-utils'
99

1010
describeWithMountingMethods('options.slots', mountingMethod => {
1111
it('mounts component with default slot if passed component in slot object', () => {
@@ -553,6 +553,8 @@ describeWithMountingMethods('options.slots', mountingMethod => {
553553
mountingMethod.name === 'renderToString',
554554
'sets a component which can access the parent component',
555555
() => {
556+
const localVue = createLocalVue()
557+
localVue.prototype.bar = 'FOO'
556558
const wrapperComponent = mount(
557559
{
558560
name: 'parentComponent',
@@ -568,12 +570,13 @@ describeWithMountingMethods('options.slots', mountingMethod => {
568570
ComponentWithParentName
569571
},
570572
slots: {
571-
default: '<component-with-parent-name />'
572-
}
573+
default: '<component-with-parent-name :foo="bar" />'
574+
},
575+
localVue
573576
}
574577
)
575578
expect(wrapperComponent.vm.childName).to.equal('component-with-parent-name')
576-
expect(wrapperComponent.html()).to.equal('<div><div foo="bar"><span baz="qux">quux</span></div></div>')
579+
expect(wrapperComponent.html()).to.equal('<div><div foo="FOO"><span baz="qux">quux</span></div></div>')
577580
}
578581
)
579582
})

0 commit comments

Comments
 (0)