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); + + }); });