forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_about_classes.js
More file actions
62 lines (51 loc) · 1.66 KB
/
13_about_classes.js
File metadata and controls
62 lines (51 loc) · 1.66 KB
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
describe("About Prototypal Inheritance (topics/13_about_prototypal_inheritance.js)", function () {
class User {
constructor(name, password) {
this.name = name;
this.password = password;
}
greet() {
return "Hello, my name is " + this.name;
}
}
class Administrator extends User {
constructor(name, password) {
super(name, password);
}
greet() {
return super.greet() + " and I'm an admin";
}
static role = "Admin";
}
const eric = new User("Eric", "password");
const john = new Administrator("John", "hardpassword");
it("defining a 'User' class", function () {
expect(__).toBe(eric.greet(), "what will Eric say?");
});
it("can change a user's password", function () {
// missing function 'changePassword' in User class!
eric.changePassword("ericPass");
expect(eric.password).toBe(
"ericPass",
"did you implement 'changePassword' method?"
);
});
it("Administrator Inherits the User class", function () {
expect(__).toBe(eric instanceof User);
expect(__).toBe(eric instanceof Administrator);
expect(__).toBe(john instanceof User);
expect(__).toBe(john instanceof Administrator);
});
it("`greet` is polymorphic", function () {
expect(__).toBe(john.greet(), "what will John say?");
});
it('a class can have a "shared" field', function () {
expect("Admin").toBe(__, "What do all Administrators have in common?");
});
it('a class can have a "shared" method', function () {
expect("Administrating...").toBe(
Administrator.__,
"https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Classes/static"
);
});
});