Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //signIn.spec.js
- import validators from '../../../validators'
- const { SignInUserValidator } = validators
- describe('test siginUserValidator', () => {
- describe('validateEmail function', () => {
- test('error when user email is not defined', () => {
- const validator = new SignInUserValidator({
- email: undefined
- })
- validator.validateEmail()
- expect(validator.errors).toEqual(['The email is required.'])
- })
- test('error when user email is not valid', () => {
- const validator = new SignInUserValidator({
- email: 'notvalidemail'
- })
- validator.validateEmail()
- expect(validator.errors).toEqual([
- 'The email must be a valid email address.'
- ])
- })
- })
- describe('validatePassword function', () => {
- test('error when user password is not present', () => {
- const validator = new SignInUserValidator({
- user: {
- password: undefined
- }
- })
- validator.validatePassword()
- expect(validator.errors).toEqual(['The password is required.'])
- })
- })
- describe('isValid function', () => {
- test('validateEmail and validatePassword function is called', () => {
- const validator = new SignInUserValidator({
- email: 'validEmail@gmail.com',
- password: 12324
- })
- jest.spyOn(validator, 'validateEmail')
- jest.spyOn(validator, 'validatePassword')
- validator.isValid()
- expect(validator.validateEmail).toHaveBeenCalled()
- expect(validator.validatePassword).toHaveBeenCalled()
- })
- test('return false if has errors', () => {
- const validator = new SignInUserValidator({
- email: 'validEmail@gmail.com',
- password: 'ss'
- })
- validator.isValid()
- expect(validator.errors.length).toBe(1)
- expect(validator.isValid()).toBeFalsy()
- })
- test('return true if no error', () => {
- const validator = new SignInUserValidator({
- email: 'validEmail@gmail.com',
- password: 12345
- })
- validator.isValid()
- expect(validator.errors.length).toBe(0)
- expect(validator.isValid()).toBeTruthy()
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement