-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
63 lines (50 loc) · 1.51 KB
/
solution.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 27: class - super inside a method (solution)
// 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;
}
}
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() { } }
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 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.parentValue;
}
}
assert.equal(new B().getMethod(), void 0);
});
});