Skip to content

Commit 22fd327

Browse files
tests: do not throw on tech/player dispose (videojs#5179)
1 parent 59c6261 commit 22fd327

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/js/resize-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class ResizeManager extends Component {
9797

9898
dispose() {
9999
if (this.resizeObserver_) {
100-
this.resizeObserver_.unobserve(this.player_.el());
100+
if (this.player_.el()) {
101+
this.resizeObserver_.unobserve(this.player_.el());
102+
}
101103
this.resizeObserver_.disconnect();
102104
}
103105

test/unit/player.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,48 @@ QUnit.test('dispose should not throw if styleEl is missing', function(assert) {
4949
assert.ok(player.el() === null, 'element disposed');
5050
});
5151

52+
QUnit.test('dispose should not throw if techEl is missing', function(assert) {
53+
const videoTag = TestHelpers.makeTag();
54+
const fixture = document.getElementById('qunit-fixture');
55+
56+
fixture.appendChild(videoTag);
57+
58+
const player = new Player(videoTag);
59+
60+
player.tech_.el_.parentNode.removeChild(player.tech_.el_);
61+
player.tech_.el_ = null;
62+
let error;
63+
64+
try {
65+
player.dispose();
66+
} catch (e) {
67+
error = e;
68+
}
69+
70+
assert.notOk(error, 'Function did not throw an error on dispose');
71+
});
72+
73+
QUnit.test('dispose should not throw if playerEl is missing', function(assert) {
74+
const videoTag = TestHelpers.makeTag();
75+
const fixture = document.getElementById('qunit-fixture');
76+
77+
fixture.appendChild(videoTag);
78+
79+
const player = new Player(videoTag);
80+
81+
player.el_.parentNode.removeChild(player.el_);
82+
player.el_ = null;
83+
let error;
84+
85+
try {
86+
player.dispose();
87+
} catch (e) {
88+
error = e;
89+
}
90+
91+
assert.notOk(error, 'Function did not throw an error on dispose');
92+
});
93+
5294
// technically, all uses of videojs.options should be replaced with
5395
// Player.prototype.options_ in this file and a equivalent test using
5496
// videojs.options should be made in video.test.js. Keeping this here

0 commit comments

Comments
 (0)