Skip to content

stub globally registered components (fix #1272) #1441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ export default function createInstance(
// root instance when it's instantiated
const instanceOptions = extractInstanceOptions(options)

const globalComponents = _Vue.options.components || {}
const componentsToStub = Object.assign(
Object.create(globalComponents),
componentOptions.components
)

const stubComponentsObject = createStubsFromStubsObject(
componentOptions.components,
componentsToStub,
// $FlowIgnore
options.stubs,
_Vue
Expand Down
22 changes: 22 additions & 0 deletions test/specs/mounting-options/stubs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,26 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
expect(wrapper.find(ToStub).exists()).to.be.false
expect(wrapper.find(Stub).exists()).to.be.true
})

it('stubs globally registered components', () => {
const ChildComponent = {
template: '<div />',
props: ['propA'],
name: 'child-component'
}
const TestComponent = {
template: '<child-component prop-a="A" />'
}

Vue.component('child-component', ChildComponent)
const wrapper = mountingMethod(TestComponent, {
stubs: {
ChildComponent: true
}
})
const result = wrapper.find(ChildComponent)
expect(result.exists()).to.be.true
expect(result.props().propA).to.equal('A')
delete Vue.options.components['child-component']
})
})