Changing the value so that the v-model is updated can be confusing:
const input = wrapper.find('input[type="text"]')
input.element.value = 'some value' // input element value is changed, v-model is not
input.trigger('input') // v-model updated
const radioInput = wrapper.find('input[type="radio"]')
radioInput.element.checked = true // input element value is changed, v-model is not
radioInput.trigger('input') // v-model not updated
radioInput.trigger('change') // v-model updated
const input = wrapper.find('input[type="text"]')
input.setValue('some value')
const radioInput = wrapper.find('input[type="radio"]')
radioInput.setChecked()
const option = wrapper.find('option')
option.setSelected()
Hi, you should take a look to mwangaben-vthelpers which provides some helpers for vue-test-utils like b.type(text, selector) :
type(text, input) {
let node = this.find(input)
node.element.value = text
node.trigger('input')
}
IMHO,
Since type reminds keydown-event, I think that type is not appropriate.
@eddyerburgh are you working on this? If not I believe I can do it
@beyersito I'm not currently working on it, it would be great if you could :)
@eddyerburgh Will do then, I'll start with setValue
I've started with setValue, I would be great if you could check if I started correctly.
I have a few doubts:
setValue could work on the following inputs: text like inputs (text, email, ...), select, checkbox. The triggered event will follow v-model source.
setChecked could work on radios and in checkboxes receiving a boolean parameter.
Should it validate that the wrapper is compatible with the method?
What to do if the wrapper is a component
Sorry to bother this much
Thanks!
I think it should work on all text control inputs, although I've only tested text and email. Can you check which elements it works on? Here's a full list of input types—https://html.spec.whatwg.org/multipage/input.html#attr-input-type-keywords
Yes, setChecked should take a boolean
Yes, it should throw an error if the wrapper element won't be affected
A component wrapper always contains an element, so it should behave the same way.
Most helpful comment
Hi, you should take a look to mwangaben-vthelpers which provides some helpers for vue-test-utils like b.type(text, selector) :