From 5c8dffa2b81fbdef01439c0514b01fefd5c3aa55 Mon Sep 17 00:00:00 2001 From: Jeremy Press Date: Mon, 4 Dec 2017 14:46:53 -0800 Subject: [PATCH] Fix: Only remove the timeupdate listener if it has been bound before (#525) --- src/lib/viewers/media/MediaBaseViewer.js | 4 ++-- .../viewers/media/__tests__/MediaBaseViewer-test.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/viewers/media/MediaBaseViewer.js b/src/lib/viewers/media/MediaBaseViewer.js index a036c2442..ed44cd5d8 100644 --- a/src/lib/viewers/media/MediaBaseViewer.js +++ b/src/lib/viewers/media/MediaBaseViewer.js @@ -481,13 +481,13 @@ class MediaBaseViewer extends BaseViewer { } /** - * Removes pause event listener + * Removes pause event listener if it exists * * @private * @return {void} */ removePauseEventListener() { - if (this.mediaEl) { + if (this.mediaEl && this.pauseListener) { this.mediaEl.removeEventListener('timeupdate', this.pauseListener); } } diff --git a/src/lib/viewers/media/__tests__/MediaBaseViewer-test.js b/src/lib/viewers/media/__tests__/MediaBaseViewer-test.js index 785d9cd38..734c1e8e6 100644 --- a/src/lib/viewers/media/__tests__/MediaBaseViewer-test.js +++ b/src/lib/viewers/media/__tests__/MediaBaseViewer-test.js @@ -462,12 +462,20 @@ describe('lib/viewers/media/MediaBaseViewer', () => { }); describe('removePauseEventListener()', () => { - it('should remove pause event listener', () => { - const pauseListener = () => {}; + it('should remove pause event listener if it exists', () => { + let pauseListener = null media.mediaEl = { removeEventListener: sandbox.stub() }; + + media.pauseListener = pauseListener; + media.removePauseEventListener(); + expect(media.mediaEl.removeEventListener).to.be.not.be.called + + pauseListener = () => {}; media.pauseListener = pauseListener; media.removePauseEventListener(); expect(media.mediaEl.removeEventListener).to.be.calledWith('timeupdate', pauseListener); + + }); });