-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path27-class-super-inside-a-method.js
47 lines (35 loc) · 1.46 KB
/
27-class-super-inside-a-method.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 27: class - super inside a method
// To do: make all tests pass, leave the assert lines unchanged!
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; } // we can`t use super without extends
}
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 this.youAreSuper; }}
class B extends A {constructor() { super(); this.youAreSuper = true; } }
class C extends B {
iAmSuper() {
return this.youAreSuper;
}
}
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.hasSuper; }}
assert.equal(new B().getMethod(), void 0);
});
});