Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. //signIn.spec.js
  2.  
  3. import validators from '../../../validators'
  4. const { SignInUserValidator } = validators
  5.  
  6. describe('test siginUserValidator', () => {
  7. describe('validateEmail function', () => {
  8. test('error when user email is not defined', () => {
  9. const validator = new SignInUserValidator({
  10. email: undefined
  11. })
  12. validator.validateEmail()
  13. expect(validator.errors).toEqual(['The email is required.'])
  14. })
  15. test('error when user email is not valid', () => {
  16. const validator = new SignInUserValidator({
  17. email: 'notvalidemail'
  18. })
  19. validator.validateEmail()
  20. expect(validator.errors).toEqual([
  21. 'The email must be a valid email address.'
  22. ])
  23. })
  24. })
  25. describe('validatePassword function', () => {
  26. test('error when user password is not present', () => {
  27. const validator = new SignInUserValidator({
  28. user: {
  29. password: undefined
  30. }
  31. })
  32. validator.validatePassword()
  33. expect(validator.errors).toEqual(['The password is required.'])
  34. })
  35. })
  36. describe('isValid function', () => {
  37. test('validateEmail and validatePassword function is called', () => {
  38. const validator = new SignInUserValidator({
  39. email: 'validEmail@gmail.com',
  40. password: 12324
  41. })
  42.  
  43. jest.spyOn(validator, 'validateEmail')
  44. jest.spyOn(validator, 'validatePassword')
  45.  
  46. validator.isValid()
  47.  
  48. expect(validator.validateEmail).toHaveBeenCalled()
  49. expect(validator.validatePassword).toHaveBeenCalled()
  50. })
  51.  
  52. test('return false if has errors', () => {
  53. const validator = new SignInUserValidator({
  54. email: 'validEmail@gmail.com',
  55. password: 'ss'
  56. })
  57.  
  58. validator.isValid()
  59.  
  60. expect(validator.errors.length).toBe(1)
  61. expect(validator.isValid()).toBeFalsy()
  62. })
  63.  
  64. test('return true if no error', () => {
  65. const validator = new SignInUserValidator({
  66. email: 'validEmail@gmail.com',
  67. password: 12345
  68. })
  69.  
  70. validator.isValid()
  71.  
  72. expect(validator.errors.length).toBe(0)
  73. expect(validator.isValid()).toBeTruthy()
  74. })
  75. })
  76. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement