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

feat: Add setValue method #557

Merged
merged 7 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ export default class Wrapper implements BaseWrapper {
this.vnode = this.vm._vnode
}

/**
* Sets input value
*/
setValue (value: string) {
this.element.value = value // input element value is changed, v-model is not
this.trigger('input')
}

/**
* Return text of wrapper element
*/
Expand Down
16 changes: 16 additions & 0 deletions test/resources/components/component-with-input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<input type="text" v-model="inputValue">
</div>
</template>

<script>
export default{
name: 'component-with-input',
data() {
return {
inputValue: undefined
}
}
}
</script>
23 changes: 23 additions & 0 deletions test/specs/wrapper/setValue.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ComponentWithInput from '~resources/components/component-with-input.vue'
import { describeWithShallowAndMount } from '~resources/utils'

describeWithShallowAndMount('setValue', (mountingMethod) => {
it('sets element value', () => {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find('input')
input.setValue('foo')

expect(input.element.value).to.equal('foo')
})

it('calls trigger with input', () => {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find('input')
sinon.spy(input, 'trigger')

input.setValue('foo')

expect(input.trigger.called).to.equal(true)
expect(input.trigger.calledWith('input')).to.equal(true)
})
})