diff --git a/src/index.js b/src/index.js index 398d7d1..a1cb7a4 100644 --- a/src/index.js +++ b/src/index.js @@ -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]; } diff --git a/test/unit.test.js b/test/unit.test.js index a4b03d4..5e093e8 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -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();