Hello, I am new to Jest and unit testing. I have a question about how to set the value of a text input using Vue Test Utils.
Here is the code for my custom text input component:
<input
v-model="local_value"
@keyup.enter="submitToParent"
:class="input_class"
:id="id"
:disabled="is_disabled"
:maxlength="max_length"
:placeholder="placeholder"
:autocomplete="(is_autocomplete) ? 'on' : 'off'"
:name="id"
:ref="id"
/>
Here is the test code I have written:
it("typing on the field should update the value correctly", async () => {
const wrapper = shallowMount(TextInput, {
propsData: {
id: "my_input",
}
})
// Find the component (which works properly), then try to insert some text
const input = wrapper.findComponent({ref: "my_input"})
input.element.value = "sample text"
input.setValue("sample text")
// The value still remains an empty string (""). Not sure what's going wrong.
console.log(wrapper.vm.local_value)
expect(wrapper.vm.local_value).toBe("sample text")
If you have any solutions to this problem, please let me know. Thank you for your time.