From eac7d38655bb35fbba2bd9ee7390db17d636930a Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 7 Jun 2018 14:29:09 +0200 Subject: [PATCH] test media-tag, and fix the bug the tests exposed --- www/assert/main.js | 23 ++++++++++++++++++++++- www/common/media-tag.js | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/www/assert/main.js b/www/assert/main.js index 657488b81..4ff862511 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -9,7 +9,8 @@ define([ '/common/common-thumbnail.js', '/common/wire.js', '/common/flat-dom.js', -], function ($, Hyperjson, Sortify, Drive, Test, Hash, Util, Thumb, Wire, Flat) { + '/common/media-tag.js', +], function ($, Hyperjson, Sortify, Drive, Test, Hash, Util, Thumb, Wire, Flat, MediaTag) { window.Hyperjson = Hyperjson; window.Sortify = Sortify; @@ -295,6 +296,26 @@ define([ !secret.hashData.present); }, "test support for ugly tracking query paramaters in url"); + assert(function (cb) { + try { + MediaTag(void 0).on('progress').on('decryption'); + return void cb(true); + } catch (e) { + console.error(e); + return void cb(false); + } + }, 'check that MediaTag does the right thing when passed no value'); + + assert(function (cb) { + try { + MediaTag(document.createElement('div')).on('progress').on('decryption'); + return void cb(true); + } catch (e) { + console.error(e); + return void cb(false); + } + }, 'check that MediaTag does the right thing when passed no value'); + assert(function (cb) { // TODO return cb(true); diff --git a/www/common/media-tag.js b/www/common/media-tag.js index 9ae19d3a8..eccb1ae8f 100644 --- a/www/common/media-tag.js +++ b/www/common/media-tag.js @@ -326,7 +326,7 @@ if (typeof(el) === "object" && el.jQuery) { el = el[0]; } // Abort smoothly if the element is not a media-tag - if (el.nodeName !== "MEDIA-TAG") { + if (!el || el.nodeName !== "MEDIA-TAG") { console.error("Not a media-tag!"); return { on: function () { return this; }