Skip to content

Commit 7dd58c4

Browse files
committed
ex-1: implement specific plumage beahvior for AfricanSwallow
1 parent 4f3c430 commit 7dd58c4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/functions-into-class-hierarchy/bird/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export class EuropeanSwallow extends Bird {
3636
}
3737
}
3838

39-
export class AfricanSwallow extends Bird {}
39+
export class AfricanSwallow extends Bird {
40+
get plumage() {
41+
return this.numberOfCoconuts > 2 ? 'tired' : 'average';
42+
}
43+
}
4044

4145
export class NorwegianBlueParrot extends Bird {}
4246

src/functions-into-class-hierarchy/bird/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ describe('EuropeanSwallow', () => {
8080
});
8181
});
8282

83+
describe('AfricanSwallow', () => {
84+
describe('plumage', () => {
85+
it('should return "tired" for more than 2 coconuts', () => {
86+
const bird = new AfricanSwallow({ type: 'AfricanSwallow', numberOfCoconuts: 3 });
87+
expect(bird.plumage).toBe('tired');
88+
});
89+
90+
it('should return "average" for 2 or less coconuts', () => {
91+
const bird = new AfricanSwallow({ type: 'AfricanSwallow', numberOfCoconuts: 2 });
92+
expect(bird.plumage).toBe('average');
93+
});
94+
});
95+
});
96+
8397
describe('createBird', () => {
8498
it('should return an instance of EuropeanSwallow for type EuropeanSwallow', () => {
8599
const bird = { type: 'EuropeanSwallow' };

0 commit comments

Comments
 (0)