From bbea5cc7cb183a2e94e20c69589b14885755ff77 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 16 Nov 2017 18:12:37 -0500 Subject: [PATCH] fix: only print element not in DOM warning on player creation (#4755) --- src/js/video.js | 10 +++++----- test/unit/video.test.js | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/js/video.js b/src/js/video.js index aaae474c1..8f45a0e0e 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -100,17 +100,17 @@ function videojs(id, options, ready) { throw new TypeError('The element or ID supplied is not valid. (videojs)'); } - // Check if element is included in the DOM - if (Dom.isEl(tag) && !document.body.contains(tag)) { - log.warn('The element supplied is not included in the DOM'); - } - // Element may have a player attr referring to an already created player instance. // If so return that otherwise set up a new player below if (tag.player || Player.players[tag.playerId]) { return tag.player || Player.players[tag.playerId]; } + // Check if element is included in the DOM + if (Dom.isEl(tag) && !document.body.contains(tag)) { + log.warn('The element supplied is not included in the DOM'); + } + options = options || {}; videojs.hooks('beforesetup').forEach(function(hookFunction) { diff --git a/test/unit/video.test.js b/test/unit/video.test.js index 3daf3d429..6f89b7ecb 100644 --- a/test/unit/video.test.js +++ b/test/unit/video.test.js @@ -65,6 +65,7 @@ function(assert) { const vid = document.createElement('video'); + vid.id = 'test_vid_id'; fixture.appendChild(vid); const player = videojs(vid); @@ -72,6 +73,8 @@ function(assert) { assert.equal(warnLogs.length, 0, 'no warn logs'); const vid2 = document.createElement('video'); + + vid2.id = 'test_vid_id2'; const player2 = videojs(vid2); assert.ok(player2, 'created player from tag'); @@ -80,6 +83,11 @@ function(assert) { 'The element supplied is not included in the DOM', 'logged the right message'); + // should only log warnings on the first creation + videojs(vid2); + videojs('test_vid_id2'); + assert.equal(warnLogs.length, 1, 'did not log another warning'); + log.warn = origWarnLog; player.dispose(); player2.dispose();