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: remove cached constructors #1059

Merged
merged 2 commits into from Dec 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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