Skip to content

Commit 4969f30

Browse files
committed
refactor: extract create wrapper logic
1 parent 063cd8f commit 4969f30

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/wrappers/wrapper.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import WrapperArray from './wrapper-array'
1717
import ErrorWrapper from './error-wrapper'
1818
import { throwError, warn } from '../lib/util'
1919
import findAll from '../lib/find'
20+
import createWrapper from './create-wrapper'
2021

2122
export default class Wrapper implements BaseWrapper {
2223
vnode: VNode;
@@ -66,7 +67,8 @@ export default class Wrapper implements BaseWrapper {
6667
Object.keys(this.vm.$style).forEach((key) => {
6768
// $FlowIgnore : Flow thinks vm is a property
6869
moduleIdent = this.vm.$style[key]
69-
// CSS Modules may be multi-class if they extend others. Extended classes should be already present in $style.
70+
// CSS Modules may be multi-class if they extend others.
71+
// Extended classes should be already present in $style.
7072
moduleIdent = moduleIdent.split(' ')[0]
7173
cssModuleIdentifiers[moduleIdent] = key
7274
})
@@ -227,9 +229,7 @@ export default class Wrapper implements BaseWrapper {
227229
}
228230
return new ErrorWrapper(typeof selector === 'string' ? selector : 'Component')
229231
}
230-
return nodes[0] instanceof Vue
231-
? new VueWrapper(nodes[0], this.options)
232-
: new Wrapper(nodes[0], this.update, this.options)
232+
return createWrapper(nodes[0], this.update, this.options)
233233
}
234234

235235
/**
@@ -238,10 +238,9 @@ export default class Wrapper implements BaseWrapper {
238238
findAll (selector: Selector): WrapperArray {
239239
const selectorType = getSelectorTypeOrThrow(selector, 'findAll')
240240
const nodes = findAll(this.vm, this.vnode, selectorType, selector)
241-
const wrappers = nodes[0] && nodes[0] instanceof Vue
242-
? nodes.map(node => new VueWrapper(node, this.options))
243-
: nodes.map(node => new Wrapper(node, this.update, this.options))
244-
241+
const wrappers = nodes.map(node =>
242+
createWrapper(node, this.update, this.options)
243+
)
245244
return new WrapperArray(wrappers)
246245
}
247246

test/unit/specs/mount/Wrapper/find.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ describe('find', () => {
138138

139139
const wrapper = mount(TestComponent)
140140
expect(wrapper.find(FunctionalComponent).vnode).to.be.an('object')
141+
expect(wrapper.find(FunctionalComponent).vm).to.be('undefined')
141142
})
142143

143144
it('returns correct number of Vue Wrappers when component has a v-for', () => {

0 commit comments

Comments
 (0)