Guest User

Untitled

a guest
Nov 16th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 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{} //changed let to class, added {}
  8. const instance = new TestClass();
  9. assert.equal(typeof instance, 'object');
  10. });
  11. it('a class is block scoped', () => {
  12. {class Inside {}} //block scoped this line
  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 = 42;
  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. const notATester = new User();
  31. assert.equal(notATester.writesTests(), false);
  32. });
  33. it('multiple methods need no commas (opposed to object notation)', function() {
  34. class User {
  35. wroteATest() { this.everWroteATest = true; }
  36. isLazy() { return this.everWroteATest !== true } //text between {} added
  37. }
  38. const tester = new User();
  39. assert.equal(tester.isLazy(), true);
  40. tester.wroteATest();
  41. assert.equal(tester.isLazy(), false);
  42. });
  43. it('anonymous class', () => {
  44. const classType = typeof class {};
  45. assert.equal(classType, 'function');
  46. });
  47. });
Add Comment
Please, Sign In to add comment