Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // 27: class - super inside a method
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('Inside a class use `super` to access parent methods', () => {
  6. it('use of `super` without `extends` fails (already when transpiling)', () => {
  7. class A {hasSuper() { return false; }}//asked to return false
  8. assert.equal(new A().hasSuper(), false);
  9. });
  10. it('`super` with `extends` calls the method of the given name of the parent class', () => {
  11. class A {hasSuper() { return true; }}
  12. class B extends A {hasSuper() { return super.hasSuper(); }} //added parentheses to give parameters
  13. assert.equal(new B().hasSuper(), true);
  14. });
  15. it('when overridden a method does NOT automatically call its super method', () => {
  16. class A {hasSuper() { return true; }}
  17. class B extends A {hasSuper() { }} //took away the object
  18. assert.equal(new B().hasSuper(), void 0);
  19. });
  20. it('`super` works across any number of levels of inheritance', () => {
  21. class A {iAmSuper() { return true; }}
  22. class B extends A {}
  23. class C extends B {iAmSuper() { return super.iAmSuper(true); }} //added 'super'
  24. assert.equal(new C().iAmSuper(), true);
  25. });
  26. it('accessing an undefined member of the parent class returns `undefined`', () => {
  27. class A {}
  28. class B extends A {getMethod() { }} //removed the object within
  29. assert.equal(new B().getMethod(), void 0);
  30. });
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement