Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 27: class - super inside a method
- // To do: make all tests pass, leave the assert lines unchanged!
- // Follow the hints of the failure messages!
- describe('Inside a class use `super` to access parent methods', () => {
- it('use of `super` without `extends` fails (already when transpiling)', () => {
- class A {hasSuper() { return false; }}
- assert.equal(new A().hasSuper(), false);
- });
- it('`super` with `extends` calls the method of the given name of the parent class', () => {
- class A { hasSuper() { return true; }}
- class B extends A { hasSuper() { return super.hasSuper(); }}
- assert.equal(new B().hasSuper(), true);
- });
- it('when overridden a method does NOT automatically call its super method', () => {
- class A {hasSuper() { return true; }}
- class B extends A {hasSuper() { return undefined; }}
- assert.equal(new B().hasSuper(), void 0);
- });
- it('`super` works across any number of levels of inheritance', () => {
- class A {iAmSuper() { return true; }}
- class B extends A {}
- class C extends B {iAmSuper() { return super.iAmSuper(); }}
- assert.equal(new C().iAmSuper(), true);
- });
- it('accessing an undefined member of the parent class returns `undefined`', () => {
- class A {}
- class B extends A {getMethod() { return super.notAFunction; }}
- assert.equal(new B().getMethod(), void 0);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement