From 1487c3a9947b0eb55c61b5d93ff9f0c69a812aeb Mon Sep 17 00:00:00 2001 From: Johann-S Date: Mon, 23 Oct 2017 09:35:27 +0200 Subject: Add `Util.jQuery` which will detect jQuery instead of relying on global `$` (#24513) --- js/tests/unit/util.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 js/tests/unit/util.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js new file mode 100644 index 000000000..c3412041e --- /dev/null +++ b/js/tests/unit/util.js @@ -0,0 +1,19 @@ +$(function () { + 'use strict' + + QUnit.module('Util') + + QUnit.test('Util.jQuery should find window.jQuery if window.$ is not available', function (assert) { + assert.expect(1) + delete window.$ + assert.strictEqual(Util.jQuery, window.jQuery) + window.$ = Util.jQuery + }) + + QUnit.test('Util.jQuery should find window.$ if window.jQuery is not available', function (assert) { + assert.expect(1) + delete window.jQuery + assert.strictEqual(Util.jQuery, window.$) + window.jQuery = Util.jQuery + }) +}) -- cgit v1.2.3 From 62fbb23ee61999e362cd8ade6073732a46466077 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 24 Oct 2017 10:12:45 +0200 Subject: Change Rollup config to wrap our dist files with jQuery instead of $ --- js/tests/unit/util.js | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 js/tests/unit/util.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js deleted file mode 100644 index c3412041e..000000000 --- a/js/tests/unit/util.js +++ /dev/null @@ -1,19 +0,0 @@ -$(function () { - 'use strict' - - QUnit.module('Util') - - QUnit.test('Util.jQuery should find window.jQuery if window.$ is not available', function (assert) { - assert.expect(1) - delete window.$ - assert.strictEqual(Util.jQuery, window.jQuery) - window.$ = Util.jQuery - }) - - QUnit.test('Util.jQuery should find window.$ if window.jQuery is not available', function (assert) { - assert.expect(1) - delete window.jQuery - assert.strictEqual(Util.jQuery, window.$) - window.jQuery = Util.jQuery - }) -}) -- cgit v1.2.3 From 988327032d6b76fdb70075feb7254bcb053ec117 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Wed, 25 Oct 2017 09:32:21 +0200 Subject: Add unit tests for util.js --- js/tests/unit/util.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 js/tests/unit/util.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js new file mode 100644 index 000000000..372c6e3f7 --- /dev/null +++ b/js/tests/unit/util.js @@ -0,0 +1,57 @@ +$(function () { + 'use strict' + + QUnit.module('util') + + QUnit.test('Util.getSelectorFromElement should return the correct element', function (assert) { + assert.expect(2) + var $el = $('
').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el[0]), 'body') + + // not found element + var $el2 = $('
').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) + }) + + QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) { + assert.expect(1) + var namePlugin = 'collapse' + var defaultType = { + toggle : 'boolean', + parent : '(string|element)' + } + var config = { + toggle: true, + parent: 777 + } + + try { + Util.typeCheckConfig(namePlugin, config, defaultType) + } catch (e) { + assert.strictEqual(e.message, 'COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".') + } + }) + + QUnit.test('Util.isElement should check if we passed an element or not', function (assert) { + assert.expect(3) + var $div = $('
').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.isElement($div), 1) + assert.strictEqual(Util.isElement($div[0]), 1) + assert.strictEqual(typeof Util.isElement({}) === 'undefined', true) + }) + + QUnit.test('Util.getUID should generate a new id uniq', function (assert) { + assert.expect(2) + var id = Util.getUID('test') + var id2 = Util.getUID('test') + + assert.ok(id !== id2, id + ' !== ' + id2) + + id = Util.getUID('test') + $('
').appendTo($('#qunit-fixture')) + + id2 = Util.getUID('test') + assert.ok(id !== id2, id + ' !== ' + id2) + }) +}) -- cgit v1.2.3