Skip to content

Commit

Permalink
fix(SizeFetcher): Corrected the given object structure to sizeChange …
Browse files Browse the repository at this point in the history
…function

The object did not have the most obvious structure and was not up to expectation
  • Loading branch information
Luc Merceron committed Apr 29, 2017
1 parent 917969a commit c9d216d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/SizeFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SizeFetcher = (SubComponent, options = { noComparison: false }) => {
if (super.componentDidMount) super.componentDidMount()
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = this.comp

this.privateSizeChanged({ clientHeight, clientWidth, scrollHeight, scrollWidth })
this.privateSizeChanged(clientHeight, clientWidth, scrollHeight, scrollWidth)
// Register an event listener on the resize so we are concious of possible size change
window.addEventListener('resize', this.privateHandleSizeMayHaveChanged.bind(this))
}
Expand All @@ -45,8 +45,9 @@ const SizeFetcher = (SubComponent, options = { noComparison: false }) => {

privateSizeChanged(clientHeight, clientWidth, scrollHeight, scrollWidth) {
const { sizeChange } = this.props

// First call of the callback, the component mounted and we need to give its size
sizeChange({ clientHeight, clientWidth, scrollHeight, scrollWidth })
sizeChange({ clientHeight: clientHeight, clientWidth: clientWidth, scrollHeight: scrollHeight, scrollWidth: scrollWidth })
// Register the dimension for future sake (comparison)
this.privateRegisterComponentInfos()
}
Expand Down
8 changes: 8 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ describe('SizeFetcher component', () => {
expect(sizeChangeFirst.mock.calls.length).toEqual(1)
expect(sizeChangeSecond.mock.calls.length).toEqual(1)
})
it('should call sizeChange with a correctly strutured object', () => {
expect(sizeChangeFirst.mock.calls).toEqual([[
{ clientHeight: 0, clientWidth: 0, scrollHeight: 0, scrollWidth: 0 }
]])
expect(sizeChangeFirst.mock.calls).toEqual([[
{ clientHeight: 0, clientWidth: 0, scrollHeight: 0, scrollWidth: 0 }
]])
})
it('should call sizeChange function when new props received if size changed or no comparison actived', () => {
WrapperEnhancedFunctionalComponent.setProps({ newProps: true })
WrapperEnhancedNormalComponent.setProps({ newProps: true })
Expand Down

0 comments on commit c9d216d

Please sign in to comment.