Validation on the frontend
As mentioned at the beginning of this chapter, we must always validate user input to make sure the data we received is valid. In this section, we will implement validation on the frontend using Vuelidate (https://monterail.github.io/vuelidate), which is a model-based validation library for Vue.js.
First of all, let's install Vuelidate
with the following command:
npm install vuelidate --save
Once it is done, let's write the unit test code for data validation.
Test the data validation
The reason we need to test the data validation is to make sure there is validation in place and user input has been properly validated before being sent to the backend. Let's add the following test to RegisterPage.spec.js
to verify that, when the value of the email address is invalid, the registrationService.register()
method won't be invoked:
... import Vuelidate from 'vuelidate' import registrationService from '@/services/registration' ... localVue.use(Vuelidate) ... // Mock dependency...