Skip to content
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

fix: allow extended components as stubs #825

Merged
merged 2 commits into from
Jul 14, 2018
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
9 changes: 5 additions & 4 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import {
} from './util'
import {
componentNeedsCompiling,
templateContainsComponent
templateContainsComponent,
isVueComponent
} from './validators'
import { compileTemplate } from './compile-template'

function isVueComponent (comp): boolean {
return comp && (comp.render || comp.template || comp.options)
function isVueComponentStub (comp): boolean {
return comp && comp.template || isVueComponent(comp)
}

function isValidStub (stub: any): boolean {
return (
(!!stub && typeof stub === 'string') ||
stub === true ||
isVueComponent(stub)
isVueComponentStub(stub)
)
}

Expand Down
6 changes: 4 additions & 2 deletions test/specs/mounting-options/stubs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ describeWithMountingMethods('options.stub', mountingMethod => {
it('accepts valid component stubs', () => {
const ComponentWithRender = { render: h => h('div') }
const ComponentWithoutRender = { template: '<div></div>' }
const ExtendedComponent = Vue.extend({ template: '<div></div>' })
const ExtendedComponent = { extends: ComponentWithRender }
const SubclassedComponent = Vue.extend({ template: '<div></div>' })
mountingMethod(ComponentWithChild, {
stubs: {
ChildComponent: ComponentAsAClass,
ChildComponent2: ComponentWithRender,
ChildComponent3: ComponentWithoutRender,
ChildComponent4: ExtendedComponent
ChildComponent4: ExtendedComponent,
ChildComponent5: SubclassedComponent
}
})
})
Expand Down