Skip to content

Commit 2dd4c4e

Browse files
committed
ex-1: expose type field as a getter at Employee
1 parent 06815da commit 2dd4c4e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/example-01/emplyees/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export class Employee {
55
this._type = type;
66
}
77

8+
get type() {
9+
return this._type;
10+
}
11+
812
validateType(arg) {
913
if (![`engineer`, `manager`, `salesman`].includes(arg))
1014
throw new Error(`Employee cannot be of type ${arg}`);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Employee } from '.';
22

33
describe('Employee', () => {
4+
it('should have a type', () => {
5+
const employee = new Employee('Kaio', 'engineer');
6+
expect(employee.type).toBe('engineer');
7+
});
8+
49
it('should throw an error if type is not valid', () => {
510
expect(() => new Employee('Kaio', 'invalid')).toThrow('Employee cannot be of type invalid');
611
});

0 commit comments

Comments
 (0)