From bc1aca1fc75b4e98f1ab58b540da9f321c6ec626 Mon Sep 17 00:00:00 2001 From: kampfkeks Date: Mon, 22 Aug 2016 11:41:42 +0200 Subject: [PATCH] Fixed a bug where creating a new mounter with options and the using it without regions would cause the options to not be used Updated tests for withOptions --- lib/__tests__/index.js | 5 +++-- lib/index.js | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/__tests__/index.js b/lib/__tests__/index.js index 254dc0a..c5973a3 100644 --- a/lib/__tests__/index.js +++ b/lib/__tests__/index.js @@ -17,8 +17,9 @@ const { describe('index', () => { describe('withOptions', () => { it('should call the given function with options', done => { - const fn = (a, options) => { - expect(a).to.be.equal('abc'); + const fn = (layoutClass, regions = {}, options) => { + expect(layoutClass).to.be.equal('abc'); + expect(regions).to.deep.equal({}); expect(options).to.deep.equal({aa: 10}); done(); }; diff --git a/lib/index.js b/lib/index.js index debda0b..cc92fe7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,9 +12,13 @@ export function mount(layoutClass, regions, options = {}) { mounter(layoutClass, regions, options); } -export function withOptions(options, fn) { - return function (...args) { - const newArgs = [ ...args, options ]; +export function withOptions(defaultOptions, fn) { + return function (layoutClass, regions, options = {}) { + const newArgs = [ + layoutClass, + regions, + { ...defaultOptions, ...options } + ]; return fn(...newArgs); }; }