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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/test-utils/src/wrapper.js
Expand Up @@ -569,10 +569,19 @@ 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.
if (tagName === 'INPUT' && this.element._vModifiers) {
lmiller1990 marked this conversation as resolved.
Show resolved Hide resolved
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
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
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