Skip to content

Commit

Permalink
fix: compile extended components (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored May 22, 2018
1 parent 5b5319d commit e1fb4a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/shared/compile-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import { compileToFunctions } from 'vue-template-compiler'

export function compileTemplate (component: Component) {
if (component.template) {
Object.assign(component, compileToFunctions(component.template))
}

if (component.components) {
Object.keys(component.components).forEach((c) => {
const cmp = component.components[c]
Expand All @@ -19,8 +23,4 @@ export function compileTemplate (component: Component) {
if (component.extendOptions && !component.options.render) {
compileTemplate(component.options)
}

if (component.template) {
Object.assign(component, compileToFunctions(component.template))
}
}
4 changes: 3 additions & 1 deletion packages/shared/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function isVueComponent (component: any) {
export function componentNeedsCompiling (component: Component) {
return component &&
!component.render &&
(component.template || component.extends) &&
(component.template ||
component.extends ||
component.extendOptions) &&
!component.functional
}

Expand Down
15 changes: 14 additions & 1 deletion test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import Component from '~resources/components/component.vue'
import ComponentWithProps from '~resources/components/component-with-props.vue'
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'
import { injectSupported, vueVersion } from '~resources/utils'
import { describeRunIf } from 'conditional-specs'
import {
describeRunIf,
itDoNotRunIf
} from 'conditional-specs'

describeRunIf(process.env.TEST_ENV !== 'node',
'mount', () => {
Expand Down Expand Up @@ -131,6 +134,16 @@ describeRunIf(process.env.TEST_ENV !== 'node',
expect(wrapper.html()).to.equal(`<div>foo</div>`)
})

// Problems accessing options of twice extended components in Vue < 2.3
itDoNotRunIf(vueVersion < 2.3,
'compiles extended components', () => {
const TestComponent = Vue.component('test-component', {
template: '<div></div>'
})
const wrapper = mount(TestComponent)
expect(wrapper.html()).to.equal(`<div></div>`)
})

it('logs if component is extended', () => {
const msg = '[vue-test-utils]: an extended child component ChildComponent has been modified to ensure it has the correct instance properties. This means it is not possible to find the component with a component selector. To find the component, you must stub it manually using the stubs mounting option.'
const ChildComponent = Vue.extend({
Expand Down

0 comments on commit e1fb4a0

Please sign in to comment.