From c1021cd5a84773170aa6e60b9e1bf0b7f8b2d836 Mon Sep 17 00:00:00 2001 From: Daniel Emery Date: Fri, 11 Jan 2019 11:47:38 +1030 Subject: [PATCH] :hammer_and_wrench: debounce-handler handle no prop case --- packages/debounce-handler/src/index.js | 14 +++++++++----- packages/debounce-handler/test/index.js | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/debounce-handler/src/index.js b/packages/debounce-handler/src/index.js index f72dfd7..d32830c 100644 --- a/packages/debounce-handler/src/index.js +++ b/packages/debounce-handler/src/index.js @@ -9,11 +9,15 @@ const debounceHandler = (handlerName, delay, leadingCall) => (Target) => { const delayValue = typeof delay === 'function' ? delay(props) : delay - this.debouncedPropInvoke = debounce( - (...args) => this.props[handlerName](...args), - delayValue, - leadingCall - ) + if (this.props[handlerName]) { + this.debouncedPropInvoke = debounce( + (...args) => this.props[handlerName](...args), + delayValue, + leadingCall + ) + } else { + this.debouncedPropInvoke = () => {} + } this.handler = (e, ...rest) => { if (e && typeof e.persist === 'function') { diff --git a/packages/debounce-handler/test/index.js b/packages/debounce-handler/test/index.js index 384cacb..b07ff51 100644 --- a/packages/debounce-handler/test/index.js +++ b/packages/debounce-handler/test/index.js @@ -104,6 +104,15 @@ describe('debounceHandler', () => { expect(mockJustDebounce.mock.calls).toMatchSnapshot() }) + it('should not error if prop is not present', () => { + const EnhancedTarget = debounceHandler('testHandler', 75, true)(Target) + const wrapper = mount( + + ) + const testHandler = wrapper.find(Target).prop('testHandler') + testHandler() + }) + describe('display name', () => { const origNodeEnv = process.env.NODE_ENV