Skip to content

Commit

Permalink
fix: stub globally registered components
Browse files Browse the repository at this point in the history
When specifying the components to stub, merge the globally registered components into the locally registered ones. (fix #1272)
  • Loading branch information
thejcannon committed Feb 22, 2020
1 parent d904f26 commit e03831f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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']
})
})

0 comments on commit e03831f

Please sign in to comment.