Skip to content

Commit 02d95ec

Browse files
committed
fix: stub globally registered components
fix vuejs#1272
1 parent d904f26 commit 02d95ec

File tree

4 files changed

+92
-46
lines changed

4 files changed

+92
-46
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: packages/server-test-utils/dist/vue-server-test-utils.js

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/test-utils/dist/vue-test-utils.js

+55-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)