diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index ea31cf192..eae0acdc0 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -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' || tagName === 'TEXTAREA') && + this.element._vModifiers && + this.element._vModifiers.lazy + ) { + this.trigger('change') + } } else { throwError(`wrapper.setValue() cannot be called on this element`) } diff --git a/test/resources/components/component-with-input.vue b/test/resources/components/component-with-input.vue index c9b8cf640..c161ee8c0 100644 --- a/test/resources/components/component-with-input.vue +++ b/test/resources/components/component-with-input.vue @@ -36,6 +36,8 @@ {{ textVal }} {{ selectVal }} {{ radioVal }} + + {{ lazy }} @@ -44,6 +46,7 @@ export default { name: 'component-with-input', data() { return { + lazy: '', checkboxVal: undefined, textVal: undefined, textareaVal: undefined, diff --git a/test/specs/wrapper/setValue.spec.js b/test/specs/wrapper/setValue.spec.js index 0f3e0bf73..867047098 100644 --- a/test/specs/wrapper/setValue.spec.js +++ b/test/specs/wrapper/setValue.spec.js @@ -1,5 +1,7 @@ import ComponentWithInput from '~resources/components/component-with-input.vue' import { describeWithShallowAndMount } from '~resources/utils' +import { itDoNotRunIf } from 'conditional-specs' +import { vueVersion } from '~resources/utils' import Vue from 'vue' describeWithShallowAndMount('setValue', mountingMethod => { @@ -28,6 +30,19 @@ describeWithShallowAndMount('setValue', mountingMethod => { expect(wrapper.text()).to.contain('input text awesome binding') }) + itDoNotRunIf( + vueVersion < 2.1, + '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')