Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // 22: class - creation
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('Class creation', () => {
  6. it('is as simple as `class XXX {}`', function() {
  7. class TestClass{};
  8. const instance = new TestClass();
  9. assert.equal(typeof instance, 'object');
  10. });
  11. it('a class is block scoped', () => {
  12.  
  13. {class Inside {}}
  14. assert.equal(typeof Inside, 'undefined');
  15. });
  16. it('the `constructor` is a special method', function() {
  17. class User {
  18. constructor(id) {
  19. this.id = id
  20. }
  21. }
  22. const user = new User(42);
  23. assert.equal(user.id, 42);
  24. });
  25. it('defining a method by writing it inside the class body', function() {
  26. class User {
  27. writesTests() {
  28. return false
  29. }
  30. }
  31. const notATester = new User();
  32. assert.equal(notATester.writesTests(), false);
  33. });
  34. it('multiple methods need no commas (opposed to object notation)', function() {
  35. class User {
  36. wroteATest() { this.everWroteATest = true; }
  37. isLazy() { return !this.everWroteATest }
  38. }
  39. const tester = new User();
  40. assert.equal(tester.isLazy(), true);
  41. tester.wroteATest();
  42. assert.equal(tester.isLazy(), false);
  43. });
  44. it('anonymous class', () => {
  45. const classType = typeof class {};
  46. assert.equal(classType, 'function');
  47. });
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement