Skip to content

Commit e03831f

Browse files
committed
fix: stub globally registered components
When specifying the components to stub, merge the globally registered components into the locally registered ones. (fix #1272)
1 parent d904f26 commit e03831f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ export default function createInstance(
5252
// root instance when it's instantiated
5353
const instanceOptions = extractInstanceOptions(options)
5454

55+
const globalComponents = _Vue.options.components || {}
56+
const componentsToStub = Object.assign(
57+
Object.create(globalComponents),
58+
componentOptions.components
59+
)
60+
5561
const stubComponentsObject = createStubsFromStubsObject(
56-
componentOptions.components,
62+
componentsToStub,
5763
// $FlowIgnore
5864
options.stubs,
5965
_Vue

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

+22
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,26 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
568568
expect(wrapper.find(ToStub).exists()).to.be.false
569569
expect(wrapper.find(Stub).exists()).to.be.true
570570
})
571+
572+
it('stubs globally registered components', () => {
573+
const ChildComponent = {
574+
template: '<div />',
575+
props: ['propA'],
576+
name: 'child-component'
577+
}
578+
const TestComponent = {
579+
template: '<child-component prop-a="A" />'
580+
}
581+
582+
Vue.component('child-component', ChildComponent)
583+
const wrapper = mountingMethod(TestComponent, {
584+
stubs: {
585+
ChildComponent: true
586+
}
587+
})
588+
const result = wrapper.find(ChildComponent)
589+
expect(result.exists()).to.be.true
590+
expect(result.props().propA).to.equal('A')
591+
delete Vue.options.components['child-component']
592+
})
571593
})

0 commit comments

Comments
 (0)