From c6ea6c2de99a82e1cf798264e87c3d057f1ae32f Mon Sep 17 00:00:00 2001 From: Alexandr Vorobey Date: Fri, 8 May 2020 20:37:23 +0300 Subject: [PATCH] fix(prepareOpts): TypeError when opts is undefined (#66) * fix(prepareOpts): TypeError when opts is undefined --- index.d.ts | 2 +- index.js | 1 + test/test.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4cf428a..25710cd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -191,7 +191,7 @@ interface Color { declare function looksSame( image1: string | Buffer | BoundedImage, image2: string | Buffer | BoundedImage, - options: LooksSameOptions, + options: LooksSameOptions | {}, callback: LooksSameCallback ): void; /** diff --git a/index.js b/index.js index 20f2f92..639048a 100644 --- a/index.js +++ b/index.js @@ -116,6 +116,7 @@ const getToleranceFromOpts = (opts) => { }; const prepareOpts = (opts) => { + opts = opts || {}; opts.tolerance = getToleranceFromOpts(opts); return _.defaults(opts, { diff --git a/test/test.js b/test/test.js index d9740ae..43a97c4 100644 --- a/test/test.js +++ b/test/test.js @@ -42,6 +42,12 @@ describe('looksSame', () => { }).to.throw(TypeError); }); + it('should work when opts is undefined', () => { + expect(() => { + looksSame(srcPath('ref.png'), srcPath('same.png'), undefined, () => {}); + }).not.to.throw(TypeError); + }); + it('should format images', (done) => { sandbox.spy(utils, 'formatImages');