Skip to content

Commit

Permalink
fix: remove cached constructors (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Dec 9, 2018
1 parent 9cbf908 commit aea1c94
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
6 changes: 5 additions & 1 deletion packages/test-utils/src/find.js
Expand Up @@ -69,7 +69,11 @@ export default function find (

if (
selector.type === COMPONENT_SELECTOR &&
selector.value.functional &&
(
selector.value.functional ||
(selector.value.options &&
selector.value.options.functional)
) &&
vueVersion < 2.3
) {
throwError(
Expand Down
23 changes: 13 additions & 10 deletions packages/test-utils/src/matches.js
Expand Up @@ -12,27 +12,30 @@ export function vmMatchesName (vm, name) {
}

function vmCtorMatches (vm, component) {
const Ctor = typeof component === 'function'
? component.options._Ctor
: component._Ctor

if (
vm.$options && vm.$options.$_vueTestUtils_original === component ||
vm.$_vueTestUtils_original === component
) {
return true
}

const Ctor = typeof component === 'function'
? component.options._Ctor
: component._Ctor

if (!Ctor) {
return false
}

const constructor = vm.constructor
return Object.keys(Ctor).some(c => {
return component.functional
? Ctor[c] === vm._Ctor[c]
: Ctor[c] === constructor
})
if (vm.constructor.extendOptions === component) {
return true
}

if (component.functional) {
return Object.keys(vm._Ctor || {}).some(c => {
return component === vm._Ctor[c].extendOptions
})
}
}

export function matches (node, selector) {
Expand Down
3 changes: 3 additions & 0 deletions packages/test-utils/src/mount.js
Expand Up @@ -54,5 +54,8 @@ export default function mount (
const root = vm.$options._isFunctionalContainer
? vm._vnode
: vm

component._Ctor = []

return createWrapper(root, wrapperOptions)
}
28 changes: 26 additions & 2 deletions test/specs/wrapper/find.spec.js
Expand Up @@ -178,7 +178,7 @@ describeWithShallowAndMount('find', mountingMethod => {
wrappers.forEach((w, i) => expect(w.classes()).to.contain(expectedClasses[i]))
})

it('returns Wrapper of Vue Component matching functional component', () => {
it('returns functional component', () => {
if (!functionalSFCsSupported) {
return
}
Expand All @@ -199,7 +199,7 @@ describeWithShallowAndMount('find', mountingMethod => {
expect(wrapper.find(FunctionalComponent).vm).to.equal(undefined)
})

it('returns Wrapper of Vue Component matching functional component with name', () => {
it('returns functional component with name', () => {
const TestFunctionalComponent = {
render: h => h('div'),
functional: true,
Expand All @@ -224,6 +224,30 @@ describeWithShallowAndMount('find', mountingMethod => {
}
})

it('returns extended functional component', () => {
const TestFunctionalComponent = Vue.extend({
render: h => h('div'),
functional: true
})
const TestComponent = {
template: '<div><test-functional-component /></div>',
components: {
TestFunctionalComponent
}
}
const wrapper = mountingMethod(TestComponent)
if (vueVersion < 2.3) {
const message =
'[vue-test-utils]: find for functional components is not supported in Vue < 2.3'
const fn = () => wrapper.find(TestFunctionalComponent)
expect(fn)
.to.throw()
.with.property('message', message)
} else {
expect(wrapper.find(TestFunctionalComponent).exists()).to.equal(true)
}
})

it('works correctly with innerHTML', () => {
const TestComponent = {
render (createElement) {
Expand Down

0 comments on commit aea1c94

Please sign in to comment.