Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // 27: class - super inside a method
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3.  
  4. describe('inside a class use `super` to access parent methods', () => {
  5.  
  6. it('use of `super` without `extends` fails (already when transpiling)', () => {
  7. class A {hasSuper() { return false; }}
  8.  
  9. assert.equal(new A().hasSuper(), false);
  10. });
  11.  
  12. it('`super` with `extends` calls the method of the given name of the parent class', () => {
  13. class A {hasSuper() { return true; }}
  14. class B extends A {hasSuper() { return super.hasSuper(); }}
  15.  
  16. assert.equal(new B().hasSuper(), true);
  17. });
  18.  
  19. it('when overridden a method does NOT automatically call its super method', () => {
  20. class A {hasSuper() { return true; }}
  21. class B extends A {hasSuper() {}}
  22.  
  23. assert.equal(new B().hasSuper(), void 0);
  24. });
  25.  
  26. it('`super` works across any number of levels of inheritance', () => {
  27. class A {iAmSuper() { return this.youAreSuper; }}
  28. class B extends A {constructor() { super(); this.youAreSuper = true; } }
  29. class C extends B {
  30. iAmSuper() {
  31. return super.iAmSuper();
  32. }
  33. }
  34.  
  35. assert.equal(new C().iAmSuper(), true);
  36. });
  37.  
  38. it('accessing an undefined member of the parent class returns `undefined`', () => {
  39. class A {}
  40. class B extends A {getMethod() {}}
  41.  
  42. assert.equal(new B().getMethod(), void 0);
  43. });
  44.  
  45. });
Add Comment
Please, Sign In to add comment