Home > database >  How to get value of input field ? Vue unit-test Vuetify
How to get value of input field ? Vue unit-test Vuetify

Time:03-22

I am trying test the value of an Iput field but somehow the .text() always returns nothing and I don't understand why or how could I get the value of the input element

file.spec.ts

const textFieldPhone = wrapper.find('[data-cy="text-field-telephone"');
await textFieldPhone.setValue('11111');

expect(wrapper.vm.$data.phoneNumber).toBe('11111'); // pass
expect(textFieldPhone.text()).toBe('11111'); // error
Error: expect(received).toBe(expected) // Object.is equality

Expected: "11111"
Received: ""
console.log(textField.html())

=> <input data-cy="text-field-telephone" id="input-32" type="text"/>

How can I get the value of the element ?

CodePudding user response:

You can try this: expect(textFieldPhone.element.value).toBe('11111')

  • Related