如何获取输入字段的值? Vue 单元测试 Vuetify
How to get value of input field ? Vue unit-test Vuetify
我正在尝试测试输入字段的值,但不知何故 .text() 总是 returns 什么都没有,我不明白为什么或如何获得输入元素的值
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"/>
如何获取元素的值?
你可以试试这个:expect(textFieldPhone.element.value).toBe('11111')
我正在尝试测试输入字段的值,但不知何故 .text() 总是 returns 什么都没有,我不明白为什么或如何获得输入元素的值
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"/>
如何获取元素的值?
你可以试试这个:expect(textFieldPhone.element.value).toBe('11111')