In my Vue 2.7.14 app I'm using Vuelidate 2.0.0. I'm trying to migrate a test from Jest to Vitest, but the v$
object is not initialised correctly in the latter case. The component has a checkbox bound to formData.accepted
validations () {
return {
formData: {
accepted: {
required,
sameAs: sameAs(true)
}
}
}
}
Vuelidate is initialised within the component as per the docs
setup () {
return {
v$: useVuelidate({ $autoDirty: true })
}
},
When I run the following test under Jest, it passes
it('click save button', async () => {
const wrapper = mount(MyComponent)
expect(wrapper.vm.v$.formData.accepted.$invalid).toBeTruthy()
await wrapper.find('[data-cy="accept-checkbox"]').trigger('click')
expect(wrapper.vm.v$.formData.accepted.$invalid).toBeFalsy()
})
However, if I run the same test using Vitest it fails because wrapper.vm.v$.formData
is undefined
because v$
is initialised to:
v$ {
"$dirty": false,
"$path": "__root",
"$model": null,
"$error": false,
"$errors": [],
"$invalid": false,
"$anyDirty": false,
"$pending": false,
"$silentErrors": [],
"$validationGroups": {}
}
By contrast, when the Jest test is run, $silentErrors
is not empty, and the following property path is (obviously) valid
v$.formData.accepted.$invalid
What should I do to ensure that v$
is initialised correctly when the test is run with Vitest?