From 22fd327076cb044c135c747086b58b7be64a747a Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 16 May 2018 12:02:41 -0400 Subject: [PATCH] tests: do not throw on tech/player dispose (#5179) --- src/js/resize-manager.js | 4 +++- test/unit/player.test.js | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/js/resize-manager.js b/src/js/resize-manager.js index 6be368999..3a56bbe8a 100644 --- a/src/js/resize-manager.js +++ b/src/js/resize-manager.js @@ -97,7 +97,9 @@ class ResizeManager extends Component { dispose() { if (this.resizeObserver_) { - this.resizeObserver_.unobserve(this.player_.el()); + if (this.player_.el()) { + this.resizeObserver_.unobserve(this.player_.el()); + } this.resizeObserver_.disconnect(); } diff --git a/test/unit/player.test.js b/test/unit/player.test.js index cfbd159a3..f2cac3a75 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -49,6 +49,48 @@ QUnit.test('dispose should not throw if styleEl is missing', function(assert) { assert.ok(player.el() === null, 'element disposed'); }); +QUnit.test('dispose should not throw if techEl is missing', function(assert) { + const videoTag = TestHelpers.makeTag(); + const fixture = document.getElementById('qunit-fixture'); + + fixture.appendChild(videoTag); + + const player = new Player(videoTag); + + player.tech_.el_.parentNode.removeChild(player.tech_.el_); + player.tech_.el_ = null; + let error; + + try { + player.dispose(); + } catch (e) { + error = e; + } + + assert.notOk(error, 'Function did not throw an error on dispose'); +}); + +QUnit.test('dispose should not throw if playerEl is missing', function(assert) { + const videoTag = TestHelpers.makeTag(); + const fixture = document.getElementById('qunit-fixture'); + + fixture.appendChild(videoTag); + + const player = new Player(videoTag); + + player.el_.parentNode.removeChild(player.el_); + player.el_ = null; + let error; + + try { + player.dispose(); + } catch (e) { + error = e; + } + + assert.notOk(error, 'Function did not throw an error on dispose'); +}); + // technically, all uses of videojs.options should be replaced with // Player.prototype.options_ in this file and a equivalent test using // videojs.options should be made in video.test.js. Keeping this here