Skip to content

Commit aea1c94

Browse files
authored
fix: remove cached constructors (#1059)
1 parent 9cbf908 commit aea1c94

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

Diff for: packages/test-utils/src/find.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ export default function find (
6969

7070
if (
7171
selector.type === COMPONENT_SELECTOR &&
72-
selector.value.functional &&
72+
(
73+
selector.value.functional ||
74+
(selector.value.options &&
75+
selector.value.options.functional)
76+
) &&
7377
vueVersion < 2.3
7478
) {
7579
throwError(

Diff for: packages/test-utils/src/matches.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,30 @@ export function vmMatchesName (vm, name) {
1212
}
1313

1414
function vmCtorMatches (vm, component) {
15-
const Ctor = typeof component === 'function'
16-
? component.options._Ctor
17-
: component._Ctor
18-
1915
if (
2016
vm.$options && vm.$options.$_vueTestUtils_original === component ||
2117
vm.$_vueTestUtils_original === component
2218
) {
2319
return true
2420
}
2521

22+
const Ctor = typeof component === 'function'
23+
? component.options._Ctor
24+
: component._Ctor
25+
2626
if (!Ctor) {
2727
return false
2828
}
2929

30-
const constructor = vm.constructor
31-
return Object.keys(Ctor).some(c => {
32-
return component.functional
33-
? Ctor[c] === vm._Ctor[c]
34-
: Ctor[c] === constructor
35-
})
30+
if (vm.constructor.extendOptions === component) {
31+
return true
32+
}
33+
34+
if (component.functional) {
35+
return Object.keys(vm._Ctor || {}).some(c => {
36+
return component === vm._Ctor[c].extendOptions
37+
})
38+
}
3639
}
3740

3841
export function matches (node, selector) {

Diff for: packages/test-utils/src/mount.js

+3
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ export default function mount (
5454
const root = vm.$options._isFunctionalContainer
5555
? vm._vnode
5656
: vm
57+
58+
component._Ctor = []
59+
5760
return createWrapper(root, wrapperOptions)
5861
}

Diff for: test/specs/wrapper/find.spec.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describeWithShallowAndMount('find', mountingMethod => {
178178
wrappers.forEach((w, i) => expect(w.classes()).to.contain(expectedClasses[i]))
179179
})
180180

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

202-
it('returns Wrapper of Vue Component matching functional component with name', () => {
202+
it('returns functional component with name', () => {
203203
const TestFunctionalComponent = {
204204
render: h => h('div'),
205205
functional: true,
@@ -224,6 +224,30 @@ describeWithShallowAndMount('find', mountingMethod => {
224224
}
225225
})
226226

227+
it('returns extended functional component', () => {
228+
const TestFunctionalComponent = Vue.extend({
229+
render: h => h('div'),
230+
functional: true
231+
})
232+
const TestComponent = {
233+
template: '<div><test-functional-component /></div>',
234+
components: {
235+
TestFunctionalComponent
236+
}
237+
}
238+
const wrapper = mountingMethod(TestComponent)
239+
if (vueVersion < 2.3) {
240+
const message =
241+
'[vue-test-utils]: find for functional components is not supported in Vue < 2.3'
242+
const fn = () => wrapper.find(TestFunctionalComponent)
243+
expect(fn)
244+
.to.throw()
245+
.with.property('message', message)
246+
} else {
247+
expect(wrapper.find(TestFunctionalComponent).exists()).to.equal(true)
248+
}
249+
})
250+
227251
it('works correctly with innerHTML', () => {
228252
const TestComponent = {
229253
render (createElement) {

0 commit comments

Comments
 (0)