Advertisement
Guest User

Untitled

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