Skip to content

Commit

Permalink
Merge pull request #9 from CAYdenberg/issue-8
Browse files Browse the repository at this point in the history
Throw a nice error message when passed null
  • Loading branch information
onury authored Apr 5, 2018
2 parents 3048933 + ae3d4a3 commit d2fecf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function hexToRGB(hex) {

// c = String (hex) | Array [r, g, b] | Object {r, g, b}
function toRGB(c) {
if (!c) {
throw new Error('Invalid color value');
}
if (Array.isArray(c)) return c;
return typeof c === 'string' ? hexToRGB(c) : [c.r, c.g, c.b];
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ describe('test: invert-color', () => {
expect(() => { invert('##631746', true); }).toThrow();
});

test('throw on other invalid color values', () => {
expect(() => { invert(null, true); }).toThrow('Invalid color value');
});

test('not throw for valid hex with/out # prefix', () => {
expect(() => { invert('123'); }).not.toThrow();
expect(() => { invert('123456'); }).not.toThrow();
Expand Down

0 comments on commit d2fecf8

Please sign in to comment.