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: find ref childComponent should be VueWrapper #267 #268

Merged
merged 1 commit into from
Dec 15, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wrappers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ export default class Wrapper implements BaseWrapper {
if (!this.isVueComponent) {
throwError('$ref selectors can only be used on Vue component wrappers')
}
if (this.vm && this.vm.$refs && selector.ref in this.vm.$refs && this.vm.$refs[selector.ref] instanceof Vue) {
return new VueWrapper(this.vm.$refs[selector.ref], this.options)
}
const nodes = findVNodesByRef(this.vnode, selector.ref)
if (nodes.length === 0) {
return new ErrorWrapper(`ref="${selector.ref}"`)
Expand Down Expand Up @@ -278,6 +281,9 @@ export default class Wrapper implements BaseWrapper {
if (!this.isVueComponent) {
throwError('$ref selectors can only be used on Vue component wrappers')
}
if (this.vm && this.vm.$refs && selector.ref in this.vm.$refs && this.vm.$refs[selector.ref] instanceof Vue) {
return new WrapperArray([new VueWrapper(this.vm.$refs[selector.ref], this.options)])
}
const nodes = findVNodesByRef(this.vnode, selector.ref)
return new WrapperArray(nodes.map(node => new Wrapper(node, this.update, this.options)))
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/specs/mount/Wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ComponentWithoutName from '~resources/components/component-without-name.v
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
import ComponentWithVFor from '~resources/components/component-with-v-for.vue'
import Component from '~resources/components/component.vue'
import VueWrapper from '~src/wrappers/vue-wrapper'
import Wrapper from '~src/wrappers/wrapper'
import ErrorWrapper from '~src/wrappers/error-wrapper'

Expand Down Expand Up @@ -172,7 +173,7 @@ describe('find', () => {

it('returns Wrapper of Vue Components matching the ref in options object', () => {
const wrapper = mount(ComponentWithChild)
expect(wrapper.find({ ref: 'child' })).to.be.instanceOf(Wrapper)
expect(wrapper.find({ ref: 'child' })).to.be.instanceOf(VueWrapper)
})

it('throws an error when ref selector is called on a wrapper that is not a Vue component', () => {
Expand Down