Skip to content

Commit ccc299b

Browse files
committed
ex-1: throw an error when accessing Bird.plumage for AfricanSwallow
1 parent 7dd58c4 commit ccc299b

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ export class Bird {
66
get plumage() {
77
switch (this.type) {
88
case 'EuropeanSwallow':
9-
throw 'oops';
109
case 'AfricanSwallow':
11-
return this.numberOfCoconuts > 2 ? 'tired' : 'average';
10+
throw 'oops';
1211
case 'NorwegianBlueParrot':
1312
return this.voltage > 100 ? 'scorched' : 'beautiful';
1413
default:

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ describe('Bird', () => {
77
expect(() => bird.plumage).toThrow('oops');
88
});
99

10-
it('should return "tired" for AfricanSwallow with more than 2 coconuts', () => {
11-
const bird = new Bird({ type: 'AfricanSwallow', numberOfCoconuts: 3 });
12-
expect(bird.plumage).toBe('tired');
13-
});
14-
15-
it('should return "average" for AfricanSwallow with 2 or less coconuts', () => {
16-
const bird = new Bird({ type: 'AfricanSwallow', numberOfCoconuts: 2 });
17-
expect(bird.plumage).toBe('average');
10+
it('should throw an error if bird type is AfricanSwallow', () => {
11+
const bird = new Bird({ type: 'AfricanSwallow' });
12+
expect(() => bird.plumage).toThrow('oops');
1813
});
1914

2015
it('should return "scorched" for NorwegianBlueParrot with voltage greater than 100', () => {

0 commit comments

Comments
 (0)