From 352e67cf0db7a927012fcf861b50dc656933fba0 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 10 Feb 2018 10:19:45 +0000 Subject: [PATCH 1/8] fix: use class component name in find --- src/lib/find-vue-components.js | 21 ++++++++++++--------- test/specs/wrapper/contains.spec.js | 6 ++---- test/specs/wrapper/find.spec.js | 22 ++++++++++------------ test/specs/wrapper/findAll.spec.js | 26 ++++++++++++-------------- test/specs/wrapper/isEmpty.spec.js | 2 +- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/lib/find-vue-components.js b/src/lib/find-vue-components.js index b43ffc670..aa25abb69 100644 --- a/src/lib/find-vue-components.js +++ b/src/lib/find-vue-components.js @@ -1,6 +1,5 @@ // @flow import { - COMPONENT_SELECTOR, FUNCTIONAL_OPTIONS, VUE_VERSION } from './consts' @@ -52,15 +51,20 @@ function findAllFunctionalComponentsFromVnode ( } export function vmCtorMatchesName (vm: Component, name: string): boolean { - return (vm.$vnode && vm.$vnode.componentOptions && + return !!((vm.$vnode && vm.$vnode.componentOptions && vm.$vnode.componentOptions.Ctor.options.name === name) || - (vm._vnode && vm._vnode.functionalOptions && - vm._vnode.functionalOptions.name === name) || - vm.$options && vm.$options.name === name + (vm._vnode && + vm._vnode.functionalOptions && + vm._vnode.functionalOptions.name === name) || + vm.$options && vm.$options.name === name || + vm.options && vm.options.name === name) } export function vmCtorMatchesSelector (component: Component, selector: Object) { - const Ctor = selector._Ctor || selector.options && selector.options._Ctor + const Ctor = selector._Ctor || (selector.options && selector.options._Ctor) + if (!Ctor) { + return false + } const Ctors = Object.keys(Ctor) return Ctors.some(c => Ctor[c] === component.__proto__.constructor) } @@ -95,6 +99,7 @@ export default function findVueComponents ( node[FUNCTIONAL_OPTIONS].name === selector.name ) } + const nameSelector = typeof selector === 'function' ? selector.options.name : selector.name const components = root._isVue ? findAllVueComponentsFromVm(root) : findAllVueComponentsFromVnode(root) @@ -102,8 +107,6 @@ export default function findVueComponents ( if (!component.$vnode && !component.$options.extends) { return false } - return selectorType === COMPONENT_SELECTOR - ? vmCtorMatchesSelector(component, selector) - : vmCtorMatchesName(component, selector.name) + return vmCtorMatchesSelector(component, selector) || vmCtorMatchesName(component, nameSelector) }) } diff --git a/test/specs/wrapper/contains.spec.js b/test/specs/wrapper/contains.spec.js index 31d345aca..09aa8fc0a 100644 --- a/test/specs/wrapper/contains.spec.js +++ b/test/specs/wrapper/contains.spec.js @@ -5,8 +5,7 @@ import FunctionalComponent from '~resources/components/functional-component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' import { functionalSFCsSupported, - describeWithShallowAndMount, - itSkipIf + describeWithShallowAndMount } from '~resources/test-utils' import ComponentWithoutName from '~resources/components/component-without-name.vue' @@ -41,8 +40,7 @@ describeWithShallowAndMount('contains', (mountingMethod) => { expect(wrapper.contains(FunctionalComponent)).to.equal(true) }) - itSkipIf(mountingMethod.name === 'shallow', - 'returns true if wrapper contains Vue class component', () => { + it('returns true if wrapper contains Vue class component', () => { const TestComponent = { template: `
diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js index 95eddff93..53bb7c1e9 100644 --- a/test/specs/wrapper/find.spec.js +++ b/test/specs/wrapper/find.spec.js @@ -10,8 +10,7 @@ import ComponentAsAClass from '~resources/components/component-as-a-class.vue' import { functionalSFCsSupported, vueVersion, - describeWithShallowAndMount, - itSkipIf + describeWithShallowAndMount } from '~resources/test-utils' describeWithShallowAndMount('find', (mountingMethod) => { @@ -109,22 +108,21 @@ describeWithShallowAndMount('find', (mountingMethod) => { expect(wrapper.find(Component).vnode).to.be.an('object') }) - itSkipIf(mountingMethod.name === 'shallow', - 'returns Wrapper of class component', () => { - const TestComponent = { - template: ` + it('returns Wrapper of class component', () => { + const TestComponent = { + template: `
`, - components: { - ComponentAsAClass - } + components: { + ComponentAsAClass } + } - const wrapper = mountingMethod(TestComponent) - expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object') - }) + const wrapper = mountingMethod(TestComponent) + expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object') + }) it('returns Wrapper of Vue Component matching functional component', () => { if (!functionalSFCsSupported()) { diff --git a/test/specs/wrapper/findAll.spec.js b/test/specs/wrapper/findAll.spec.js index 78928f6cc..db74f064b 100644 --- a/test/specs/wrapper/findAll.spec.js +++ b/test/specs/wrapper/findAll.spec.js @@ -8,8 +8,7 @@ import FunctionalComponent from '~resources/components/functional-component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' import { functionalSFCsSupported, - describeWithShallowAndMount, - itSkipIf + describeWithShallowAndMount } from '~resources/test-utils' describeWithShallowAndMount('findAll', (mountingMethod) => { @@ -195,22 +194,21 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { expect(wrapper.findAll(ComponentWithoutName).length).to.equal(3) }) - itSkipIf(mountingMethod.name === 'shallow', - 'returns Wrapper of class component', () => { - const TestComponent = { - template: ` + it('returns Wrapper of class component', () => { + const TestComponent = { + template: `
`, - components: { - ComponentAsAClass - } - } - - const wrapper = mountingMethod(TestComponent) - expect(wrapper.findAll(ComponentAsAClass).length).to.equal(1) - }) + components: { + ComponentAsAClass + } + } + + const wrapper = mountingMethod(TestComponent) + expect(wrapper.findAll(ComponentAsAClass).length).to.equal(1) + }) it('returns Wrapper of Vue Component matching functional component', () => { if (!functionalSFCsSupported()) { diff --git a/test/specs/wrapper/isEmpty.spec.js b/test/specs/wrapper/isEmpty.spec.js index 99d89ea0e..d05f7c62b 100644 --- a/test/specs/wrapper/isEmpty.spec.js +++ b/test/specs/wrapper/isEmpty.spec.js @@ -23,7 +23,7 @@ describeWithShallowAndMount('isEmpty', (mountingMethod) => { expect(wrapper.find('svg').isEmpty()).to.equal(true) }) - it.skip('returns false if innerHTML is not empty', () => { + it('returns false if innerHTML is not empty', () => { const TestComponent = { render (createElement) { return createElement('div', { From 1ace942f43b35c0a10921d2af18de01e61510c3c Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 10 Feb 2018 10:30:00 +0000 Subject: [PATCH 2/8] test: run shallow and mount in slots test --- .../components/component-as-a-class.vue | 2 +- test/specs/mounting-options/slots.spec.js | 84 ++++++++++--------- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/test/resources/components/component-as-a-class.vue b/test/resources/components/component-as-a-class.vue index f92e973d2..e8357be48 100644 --- a/test/resources/components/component-as-a-class.vue +++ b/test/resources/components/component-as-a-class.vue @@ -1,5 +1,5 @@