diff --git a/test/tests.html b/test/tests.html index aeb9e917..a1146d61 100644 --- a/test/tests.html +++ b/test/tests.html @@ -4,6 +4,8 @@ h5ai test suite - + + + diff --git a/test/tests/premisses.js b/test/tests/premisses.js index 43ba34d2..abfc8bec 100644 --- a/test/tests/premisses.js +++ b/test/tests/premisses.js @@ -8,14 +8,3 @@ test('window is global object', () => { test('document is global object', () => { assert.equal(typeof global.document, 'object'); }); - -test('jQuery and $ are global functions', () => { - assert.equal(typeof global.jQuery, 'function'); - assert.equal(global.jQuery.fn.jquery, '2.2.4'); - assert.equal(global.jQuery, global.$); -}); - -test('_ is global function', () => { - assert.equal(typeof global._, 'function'); - assert.equal(global._.VERSION, '4.13.1'); -}); diff --git a/test/tests/unit/core/event.js b/test/tests/unit/core/event.js index a0157e0a..c1900dda 100644 --- a/test/tests/unit/core/event.js +++ b/test/tests/unit/core/event.js @@ -6,17 +6,13 @@ test('event is object', () => { }); test('event has the right props', () => { - assert.deepEqual(Object.keys(event), ['sub', 'unsub', 'pub']); + assert.deepEqual(Object.keys(event), ['sub', 'pub']); }); test('event.sub is function', () => { assert.equal(typeof event.sub, 'function'); }); -test('event.unsub is function', () => { - assert.equal(typeof event.unsub, 'function'); -}); - test('event.pub is function', () => { assert.equal(typeof event.pub, 'function'); }); diff --git a/test/util/pin.js b/test/util/pin.js index 952e57d5..ff9d3a84 100644 --- a/test/util/pin.js +++ b/test/util/pin.js @@ -1,6 +1,6 @@ const win = global.window; const doc = win.document; -const jq = win.jQuery; + let title; let htmlId; let htmlClasses; @@ -8,24 +8,48 @@ let bodyId; let bodyClasses; let $pinnedElements; -function pinHtml() { - title = doc.title; - htmlId = jq('html').attr('id'); - htmlClasses = jq('html').attr('class'); - bodyId = jq('body').attr('id'); - bodyClasses = jq('body').attr('class'); - $pinnedElements = jq('head,body').children(); -} +const attr = (el, name, value) => { + if (typeof el === 'string') { + el = doc.querySelector(el); + } + if (value === undefined) { + return el.getAttribute(name); + } + if (value === null) { + return el.removeAttribute(name); + } + return el.setAttribute(name, value); +}; -function restoreHtml() { +const rootChildren = () => { + return [ + ...doc.querySelector('head').childNodes, + ...doc.querySelector('body').childNodes + ]; +}; + +const pinHtml = () => { + title = doc.title; + htmlId = attr('html', 'id'); + htmlClasses = attr('html', 'class'); + bodyId = attr('body', 'id'); + bodyClasses = attr('body', 'class'); + $pinnedElements = rootChildren(); +}; + +const restoreHtml = () => { doc.title = title; - jq('html').attr('id', htmlId); - jq('html').attr('class', htmlClasses); - jq('body').attr('id', bodyId); - jq('body').attr('class', bodyClasses); - jq('head,body').children().not($pinnedElements).remove(); + attr('html', 'id', htmlId); + attr('html', 'class', htmlClasses); + attr('body', 'id', bodyId); + attr('body', 'class', bodyClasses); + rootChildren().forEach(el => { + if ($pinnedElements.indexOf(el) <= 0) { + el.remove(); + } + }); win.localStorage.clear(); -} +}; module.exports = { pinHtml,