diff --git a/package.json b/package.json index 68f173b..9676303 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,8 @@ "react-dom": "0.14.0", "rimraf": "2.4.3", "sinon": "1.17.1" + }, + "dependencies": { + "hoist-non-react-statics": "^1.2.0" } } diff --git a/src/connectToStores.js b/src/connectToStores.js index 2a04c37..1618401 100644 --- a/src/connectToStores.js +++ b/src/connectToStores.js @@ -47,6 +47,7 @@ */ import React from 'react' +import statics from 'hoist-non-react-statics' import { assign, isFunction } from './functions' function connectToStores(Spec, Component = Spec) { @@ -107,6 +108,12 @@ function connectToStores(Spec, Component = Spec) { StoreConnection.contextTypes = Component.contextTypes } + statics(StoreConnection, Spec, { + getStores: true, + getPropsFromStores: true + }) + + return StoreConnection } diff --git a/test/connect-to-stores-test.js b/test/connect-to-stores-test.js index 73cd780..4549e0b 100644 --- a/test/connect-to-stores-test.js +++ b/test/connect-to-stores-test.js @@ -91,6 +91,38 @@ export default { assert.throws(() => connectToStores(BadComponentOne), 'expects the wrapped component to have a static getStores() method') }, + 'static methods on wrapped component are copied to StoreConnection component'() { + + let outsideFunction = sinon.spy(); + + const ComponentWithStatics = React.createClass({ + statics: { + getStores() { + return [testStore] + }, + getPropsFromStores(props) { + return testStore.getState() + }, + foo() { + outsideFunction() + } + }, + render() { + return React.createElement('div', null, 'statics') + } + }) + + const wrappedComponent = connectToStores(ComponentWithStatics) + + + assert.isFunction(wrappedComponent.foo, 'expects foo to also be a function on the wrapped component') + assert.isNotFunction(wrappedComponent.getPropsFromStores, 'expects getPropsFromStores to not be copied') + assert.isNotFunction(wrappedComponent.getStores, 'expects getStores to not be copied') + + wrappedComponent.foo() + assert.strictEqual(outsideFunction.called, true, 'expects the function outside to have been called') + }, + 'element mounts and unmounts'() { const div = document.createElement('div')