Skip to content

Commit

Permalink
Fix #50 / props and context to load function parameters (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien JUIF authored Feb 22, 2017
1 parent eb7262d commit 63627ce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ exports.default = function (ComposedComponent) {
value: function componentWillMount() {
// Load from hoc argument
if (isFunction(load)) {
load();
load(this.props, this.context);
}

// Load from props
if (this.omitLoadInProps(this.props)) {
this.props[loadFunctionName]();
this.props[loadFunctionName](this.props, this.context);
}
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hoc-react-loader",
"version": "3.1.2",
"version": "3.2.0",
"description": "Higher order component to call a load function from props at mount.",
"main": "build/index.js",
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/core.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export default (
componentWillMount() {
// Load from hoc argument
if (isFunction(load)) {
load()
load(this.props, this.context)
}

// Load from props
if (this.omitLoadInProps(this.props)) {
this.props[loadFunctionName]()
this.props[loadFunctionName](this.props, this.context)
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import blanket from 'blanket' // eslint-disable-line
import loader from './index'
import TailSpin from './TailSpin'


const Component = () => <div />
const LoadingIndicator = () => <div />
const getWrapped = (config, props) => {
Expand Down Expand Up @@ -151,13 +150,16 @@ describe('react-loader', () => {
// Mount
const loadProp = spy(() => {})
const loadParam = spy(() => {})
const loaded = getWrapped({ load: loadParam }, { load: loadProp })
const props = { prop1: 'prop1', load: loadProp }
const loaded = getWrapped({ load: loadParam }, props)

// Load function is called
// Graphic component isn't called
// Loader should be Dots
loadProp.should.have.been.called.once
loadProp.should.have.been.called.with(props)
loadParam.should.have.been.called.once
loadParam.should.have.been.called.with(props)
expect(loaded.find(Component).node).to.be.undefined
loaded.find(TailSpin).node.should.exists
})
Expand All @@ -166,12 +168,14 @@ describe('react-loader', () => {
// Mount
const loadProp = spy(() => {})
const loadPropName = 'customLoadFunction'
const loaded = getWrapped({ load: loadPropName }, { [loadPropName]: loadProp })
const props = { prop1: 'prop1', [loadPropName]: loadProp }
const loaded = getWrapped({ load: loadPropName }, props)

// Load function is called
// Graphic component isn't called
// Loader should be Dots
loadProp.should.have.been.called.once
loadProp.should.have.been.called.with(props)
expect(loaded.find(Component).node).to.be.undefined
loaded.find(TailSpin).node.should.exists
})
Expand Down

0 comments on commit 63627ce

Please sign in to comment.