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: support lazy modifier with setValue #1467

Merged
merged 5 commits into from
Mar 13, 2020
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
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' || tagName === 'TEXTAREA') &&
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
15 changes: 15 additions & 0 deletions test/specs/wrapper/setValue.spec.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down Expand Up @@ -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')
Expand Down