Skip to content

Commit 4338403

Browse files
authored
fix: stub dynamic components (#1051)
1 parent fb7a66c commit 4338403

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ function isConstructor (el) {
5050
return typeof el === 'function'
5151
}
5252

53+
function isComponentOptions (el) {
54+
return typeof el === 'object' && (el.template || el.render)
55+
}
56+
5357
export function patchRender (_Vue, stubs, stubAllComponents) {
5458
// This mixin patches vm.$createElement so that we can stub all components
5559
// before they are rendered in shallow mode. We also need to ensure that
@@ -60,7 +64,10 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
6064
function patchRenderMixin () {
6165
const vm = this
6266

63-
if (vm.$options.$_doNotStubChildren || vm._isFunctionalContainer) {
67+
if (
68+
vm.$options.$_doNotStubChildren ||
69+
vm.$options._isFunctionalContainer
70+
) {
6471
return
6572
}
6673

@@ -73,12 +80,11 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
7380
return originalCreateElement(el, ...args)
7481
}
7582

76-
if (isConstructor(el)) {
83+
if (isConstructor(el) || isComponentOptions(el)) {
7784
if (stubAllComponents) {
7885
const stub = createStubFromComponent(el, el.name || 'anonymous')
7986
return originalCreateElement(stub, ...args)
8087
}
81-
8288
const Constructor = shouldExtend(el, _Vue) ? extend(el, _Vue) : el
8389

8490
return originalCreateElement(Constructor, ...args)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describeWithMountingMethods('options.slots', mountingMethod => {
5656
}
5757
})
5858

59-
it('mounts component with default slot if passed object with template prop in slot object', () => {
59+
it('mounts component with default slot if passed compiled options in slot object', () => {
6060
const compiled = compileToFunctions('<div id="div" />')
6161
const wrapper = mountingMethod(ComponentWithSlots, {
6262
slots: { default: [compiled] }

Diff for: test/specs/shallow-mount.spec.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
454454
const TestComponent = {
455455
template: `
456456
<div>
457-
<ChildComponent text="normal" />
458-
<component :is="dataComponent" text="data" />
459-
<component :is="computedComponent" text="computed" />
460-
<component :is="methodComponent()" text="method" />
457+
<ChildComponent />
458+
<component :is="dataComponent" />
459+
<component :is="computedComponent" />
460+
<component :is="methodComponent()" />
461461
</div>
462462
`,
463463
components: { ChildComponent },
@@ -481,7 +481,13 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
481481
}
482482
}
483483
const wrapper = shallowMount(TestComponent)
484-
expect(wrapper.text()).to.equal('')
485-
expect(wrapper.findAll(ChildComponent).length).to.equal(4)
484+
expect(wrapper.html()).to.equal(
485+
'<div>' +
486+
'<childcomponent-stub></childcomponent-stub> ' +
487+
'<anonymous-stub></anonymous-stub> ' +
488+
'<anonymous-stub></anonymous-stub> ' +
489+
'<anonymous-stub></anonymous-stub>' +
490+
'</div>'
491+
)
486492
})
487493
})

0 commit comments

Comments
 (0)