Skip to content

Commit 679b452

Browse files
committed
ex-2: update Employee to use delegated capitalized type
1 parent d83fe11 commit 679b452

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

src/example-02/emplyees/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ export class Employee {
1717
return this._type.toString();
1818
}
1919

20-
get capitalizedType() {
21-
return this.typeString.charAt(0).toUpperCase() + this.typeString.substr(1).toLowerCase();
22-
}
23-
2420
validateType(arg) {
2521
if (![`engineer`, `manager`, `salesman`].includes(arg))
2622
throw new Error(`Employee cannot be of type ${arg}`);
2723
}
2824

2925
toString() {
30-
return `${this._name} (${this.capitalizedType})`;
26+
return `${this._name} (${this.type.capitalizedName})`;
3127
}
3228
}

src/example-02/emplyees/index.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ describe('Employee', () => {
66
expect(() => new Employee('Kaio', 'invalid')).toThrow('Employee cannot be of type invalid');
77
});
88

9-
it('should return the capitalized type', () => {
10-
const employee = new Employee('Kaio', new EmployeeType('engineer'));
11-
expect(employee.capitalizedType).toBe('Engineer');
12-
});
13-
149
describe('toString', () => {
1510
it('should return the name and type', () => {
1611
const employee = new Employee('Kaio', new EmployeeType('engineer'));

0 commit comments

Comments
 (0)