Working on a project with Vue, I have implemented some radio inputs:
<label>
<input
v-model="myProperty"
v-bind:value="true"
name="myProperty"
type="radio"
> True
</label>
<label>
<input
v-model="myProperty"
v-validate="input.rules ? input.rules : ''"
v-bind:value="false"
name="myProperty"
type="radio"
> False
</label>
When testing the functionality using vue-test-utils
and jest
, I encountered an issue in selecting and assigning a value to my radio field:
let myProperty = wrapper.find('[name="myProperty"]')
myProperty.setChecked(false)
Although the documentation suggests this method should work, it resulted in an error message:
[vue-test-utils]: wrapper.setChecked() must be passed a boolean
Interestingly, setting the value as true
worked fine. I also attempted setting the value as string 'false'
:
myProperty.setChecked('false')
But again, received the same error regarding passing a boolean value. So how can I correctly select the desired radio input in vue-test-utils
when the value is set to false
? What if the radio inputs have string values instead?