SHARE
TWEET

Untitled

a guest Aug 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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; }}
  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(); }}
  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() { return undefined; }}
  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(); }}
  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() { return super.notAFunction; }}
  29.     assert.equal(new B().getMethod(), void 0);
  30.   });
  31. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top