Skip to content

Commit 71528f0

Browse files
committed
fix missing default value on non-exist size key. change unittest according to default value change, removed redundant test.
1 parent 93989ea commit 71528f0

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/components/avatar/__tests__/index.spec.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,8 @@ describe('Avatar Badge', () => {
6262

6363
describe('badgeProps.size, supports enum or number', () => {
6464
it('should return 10 as the size number given', () => {
65-
const uut = new Avatar({badgeProps: {size: 10}});
66-
expect(uut.getBadgeSize()).toEqual(10);
67-
});
68-
69-
it('should return 876 as the size number given', () => {
70-
const uut = new Avatar({badgeProps: {size: 876}});
71-
expect(uut.getBadgeSize()).toEqual(876);
65+
const uut = new Avatar({badgeProps: {size: 99}});
66+
expect(uut.getBadgeSize()).toEqual(99);
7267
});
7368

7469
it('should return 0 as the given size number', () => {
@@ -89,10 +84,10 @@ describe('Avatar Badge', () => {
8984
expect(uut.getBadgeSize()).toEqual(BADGE_SIZES[lastSizeKey]);
9085
});
9186

92-
it('should return undefined for a non-exist size type', () => {
87+
it('should return a default value from Badge for a non-exist size type', () => {
9388
const sizeKey = '!NOT_A_VALID_ENUM$';
9489
const uut = new Avatar({badgeProps: {size: sizeKey}});
95-
expect(uut.getBadgeSize()).toBeUndefined();
90+
expect(typeof uut.getBadgeSize()).toBe('number');
9691
});
9792
});
9893
});

src/components/avatar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ class Avatar extends PureComponent<AvatarPropTypes> {
224224

225225
getBadgeSize = () => {
226226
const badgeSize = _.get(this.props, 'badgeProps.size', DEFAULT_BADGE_SIZE);
227-
227+
228228
if (_.isString(badgeSize)) {
229-
return BADGE_SIZES[badgeSize];
229+
return BADGE_SIZES[badgeSize] || BADGE_SIZES[DEFAULT_BADGE_SIZE];
230230
}
231231
return badgeSize;
232232
}

0 commit comments

Comments
 (0)