diff --git a/src/SizeFetcher.js b/src/SizeFetcher.js index ddcf10a..54a33f7 100644 --- a/src/SizeFetcher.js +++ b/src/SizeFetcher.js @@ -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)) } @@ -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() } diff --git a/src/index.test.js b/src/index.test.js index 2ff42aa..3099c8e 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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 })