Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 16 additions & 2 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,24 @@ export default class Wrapper implements BaseWrapper {
tagName === 'TEXTAREA' ||
tagName === 'SELECT'
) {
const event = tagName === 'SELECT' ? 'change' : 'input'
// $FlowIgnore
this.element.value = value
this.trigger(event)

if (tagName === 'SELECT') {
this.trigger('change')
} else {
this.trigger('input')
}

// for v-model.lazy, we need to trigger a change event, too.
// $FlowIgnore
if (
tagName === 'INPUT' &&
this.element._vModifiers &&
this.element._vModifiers.lazy
) {
this.trigger('change')
}
} else {
throwError(`wrapper.setValue() cannot be called on this element`)
}
Expand Down
3 changes: 3 additions & 0 deletions test/resources/components/component-with-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
{{ textVal }}
{{ selectVal }}
{{ radioVal }}
<input id="lazy" type="text" v-model.lazy="lazy" />
{{ lazy }}
</div>
</template>

Expand All @@ -44,6 +46,7 @@ export default {
name: 'component-with-input',
data() {
return {
lazy: '',
checkboxVal: undefined,
textVal: undefined,
textareaVal: undefined,
Expand Down
9 changes: 9 additions & 0 deletions test/specs/wrapper/setValue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ describeWithShallowAndMount('setValue', mountingMethod => {
expect(wrapper.text()).to.contain('input text awesome binding')
})

it('updates dom with input v-model.lazy', async () => {
const wrapper = mountingMethod(ComponentWithInput)
const input = wrapper.find('input#lazy')
input.setValue('lazy')
await Vue.nextTick()

expect(wrapper.text()).to.contain('lazy')
})

it('sets element of select value', () => {
const wrapper = mountingMethod(ComponentWithInput)
const select = wrapper.find('select')
Expand Down