Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. const {
  2. User,
  3. Cat
  4. } = require('../src/class');
  5.  
  6. /* eslint-disable no-undef */
  7. describe('classes', () => {
  8. describe('User', () => {
  9. it('should be a valid JS class', () => {
  10. expect(typeof User).toBe('function');
  11. expect(Array.isArray(new User({}))).toBe(false);
  12. expect(typeof new User({})).toBe('object');
  13. });
  14.  
  15. it('should set an email and password property from the provided options object', () => {
  16. const user = new User({
  17. email: 'ben@lambdaschool.com',
  18. password: 'correcthorsebatterystaple'
  19. });
  20. expect(user.email).toBe('ben@lambdaschool.com');
  21. expect(user.password).toBe('correcthorsebatterystaple');
  22. expect(Object.keys(user).length).toBe(2);
  23. });
  24.  
  25. it('should have a working comparePasswords method that returns a boolean value', () => {
  26. const user = new User({
  27. email: 'ben@lambdaschool.com',
  28. password: 'correcthorsebatterystaple'
  29. });
  30.  
  31. expect(typeof user.comparePasswords).toBe('function');
  32. expect(user.comparePasswords('sup')).toBe(false);
  33. expect(user.comparePasswords('correcthorsebatterystaple')).toBe(true);
  34. expect(user.comparePasswords()).toBe(false);
  35. });
  36. });
  37. describe('Cat', () => {
  38. it('should have the properties name and age and the methods growOlder and meow', () => {
  39. const snowball = new Cat({
  40. name: 'Snowball II',
  41. age: 5
  42. });
  43. expect(snowball).toHaveProperty('name');
  44. expect(snowball).toHaveProperty('age');
  45. expect(typeof snowball.growOlder).toBe('function');
  46. expect(typeof snowball.meow).toBe('function');
  47. });
  48. it('should inherit properties and methods from Animal', () => {
  49. const snowball = new Cat({
  50. name: 'Snowball II',
  51. age: 5
  52. });
  53. expect(Object.prototype.hasOwnProperty.call(Object.getPrototypeOf(snowball), 'growOlder')).toBe(false);
  54. expect(snowball.age).toBe(5);
  55. expect(snowball.growOlder()).toBe(6);
  56. });
  57. });
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement