From aa7f3a8609e755c8ea271b11bbbbeead51da5030 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 3 Jun 2019 12:16:43 +0200 Subject: [PATCH] fix Color(null) not working --- index.js | 2 +- test/index.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index abaa7fe..c756588 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ function Color(obj, model) { var i; var channels; - if (typeof obj === 'undefined') { + if (obj == null) { // eslint-disable-line no-eq-null,eqeqeq this.model = 'rgb'; this.color = [0, 0, 0]; this.valpha = 1; diff --git a/test/index.js b/test/index.js index bc563bc..b07a9a0 100644 --- a/test/index.js +++ b/test/index.js @@ -16,6 +16,14 @@ it('Color() instance', function () { notStrictEqual(c.rgb(), c.rgb()); }); +it('Color() instance (null)', function () { + ok((new Color(null)) instanceof Color); +}); + +it('Color() instance (undefined)', function () { + ok((new Color(undefined)) instanceof Color); +}); + it('Immutability', function () { var c = Color(0xFF0000); ok(c !== c.rgb());