From eab9da5beb5a2fdba8be4e54dfcdac0de4eba2f6 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Sat, 11 Aug 2018 22:40:47 +0200 Subject: [PATCH] fix(util): use querySelector for ids --- js/src/util.js | 2 +- js/tests/unit/util.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/src/util.js b/js/src/util.js index 3008c227851a..8165ab46f6bb 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -84,7 +84,7 @@ const Util = (($) => { } const validSelector = selector - if (selector.charAt(0) === '#') { + if (selector.charAt(0) === '#' && selector.indexOf(',') === -1) { selector = selector.substr(1) method = 'getElementById' } diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js index 49252701a501..4f44c29073f2 100644 --- a/js/tests/unit/util.js +++ b/js/tests/unit/util.js @@ -32,6 +32,19 @@ $(function () { assert.ok(spy.called) }) + QUnit.test('Util.getSelectorFromElement should use querySelector when there are multi ids', function (assert) { + assert.expect(2) + + var spy = sinon.spy(document, 'querySelector') + + var $el = $('
').appendTo($('#qunit-fixture')) + $('
').appendTo($('#qunit-fixture')) + $('
').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.getSelectorFromElement($el[0]), '#j7, #j8') + assert.ok(spy.called) + }) + QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) { assert.expect(1) var namePlugin = 'collapse'