From edef178356a33974daca7416e2dcb9515a28d072 Mon Sep 17 00:00:00 2001 From: Joel Mertanen Date: Tue, 7 May 2019 11:45:08 +0300 Subject: [PATCH] fix(lib): allow es6 modules to mapDispatchToTarget --- src/components/connector.js | 4 ++-- test/components/connector.spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/connector.js b/src/components/connector.js index 8d792b8..8f3fb2f 100644 --- a/src/components/connector.js +++ b/src/components/connector.js @@ -15,7 +15,7 @@ export default function Connector(store) { let finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget; - const finalMapDispatchToTarget = isPlainObject(mapDispatchToTarget) ? + const finalMapDispatchToTarget = isObject(mapDispatchToTarget) && !isFunction(mapDispatchToTarget) ? wrapActionCreators(mapDispatchToTarget) : mapDispatchToTarget || defaultMapDispatchToTarget; @@ -25,7 +25,7 @@ export default function Connector(store) { ); invariant( - isPlainObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget), + isObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget), 'mapDispatchToTarget must be a plain Object or a Function. Instead received %s.', finalMapDispatchToTarget ); diff --git a/test/components/connector.spec.js b/test/components/connector.spec.js index 7c03fcd..e2da408 100644 --- a/test/components/connector.spec.js +++ b/test/components/connector.spec.js @@ -114,6 +114,16 @@ describe('Connector', () => { expect(receivedDispatch).toBe(store.dispatch); }); + it('Should allow ES6 modules', () => { + // The tests are run in Node, so we are unable to use actual ES6 modules. We get quite + // close by emulating it + class FakeModule { + prop() {} + }; + const fakeModule = new FakeModule(); + expect(() => connect(() => ({}), fakeModule)(targetObj)).toNotThrow(); + }); + it('Should provide state slice, bound actions and previous state slice to target (function)', () => { const targetFunc = sinon.spy();