From 904e3c249ae073d0829c165ff5be119f7bfbac7c Mon Sep 17 00:00:00 2001 From: Marc Hughes Date: Fri, 20 Oct 2017 17:27:22 -0400 Subject: [PATCH] fix(repo): Guard against an undefined player (#67) * Guard against an undefined player * Added test for undefined player in detachHandlersFromPlayer --- src/mixins/playable.js | 6 ++++-- src/mixins/playable.test.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mixins/playable.js b/src/mixins/playable.js index e3efa31..2058b90 100644 --- a/src/mixins/playable.js +++ b/src/mixins/playable.js @@ -12,8 +12,10 @@ export default { player.oncancel = props.onCancel; }, detachHandlersFromPlayer(player) { - player.onfinish = null; - player.oncancel = null; + if (player) { + player.onfinish = null; + player.oncancel = null; + } }, notifyHandlers(event) { const { player } = this.state; diff --git a/src/mixins/playable.test.js b/src/mixins/playable.test.js index 1a22ac0..dcb8c12 100644 --- a/src/mixins/playable.test.js +++ b/src/mixins/playable.test.js @@ -40,6 +40,10 @@ describe('playable', () => { expect(player.onfinish).toBe(null); expect(player.oncancel).toBe(null); }); + + it('will not throw exception on undefined player', () => { + playable.detachHandlersFromPlayer(undefined); + }); }); describe('notifyHandlers', () => {