Skip to content

Commit 700f17b

Browse files
committed
Handle invalid opacity
1 parent 55deea8 commit 700f17b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/theming/src/utils/getColor.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,13 @@ describe('getColor', () => {
354354
it('throws an error if shade is invalid', () => {
355355
expect(() => getColor({ theme: DEFAULT_THEME, hue: 'blue', shade: NaN })).toThrow(TypeError);
356356
});
357+
358+
it('throws an error if transparency is invalid', () => {
359+
const invalid = DEFAULT_THEME.opacity[100] + 1;
360+
361+
expect(() => getColor({ theme: DEFAULT_THEME, hue: 'blue', transparency: invalid })).toThrow(
362+
Error
363+
);
364+
});
357365
});
358366
});

packages/theming/src/utils/getColor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ const toColor = (
112112
if (retVal && transparency) {
113113
const alpha = transparency > 1 ? opacity[transparency] : transparency;
114114

115+
if (alpha === undefined) {
116+
throw new Error('Error: invalid `transparency` parameter');
117+
}
118+
115119
retVal = rgba(retVal, alpha);
116120
}
117121

0 commit comments

Comments
 (0)