diff options
| author | Johann-S <[email protected]> | 2018-11-08 13:43:23 +0100 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-20 22:05:45 +0200 |
| commit | 57d50b2134077f3ef93757b52ddf51a86632e92c (patch) | |
| tree | 012581acfe8c3a7ae3ed5dc14af557a787253d51 | |
| parent | 6cfc78f2d95eca0b6fc6d0a19a76a1102f8c2254 (diff) | |
| download | bootstrap-57d50b2134077f3ef93757b52ddf51a86632e92c.tar.xz bootstrap-57d50b2134077f3ef93757b52ddf51a86632e92c.zip | |
Improve manipulator coverage
| -rw-r--r-- | js/src/dom/manipulator.js | 11 | ||||
| -rw-r--r-- | js/tests/unit/dom/manipulator.js | 7 |
2 files changed, 10 insertions, 8 deletions
diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index b9135aa79..d100a9873 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -63,13 +63,10 @@ const Manipulator = { } } - for (const key in attributes) { - if (!Object.prototype.hasOwnProperty.call(attributes, key)) { - continue - } - - attributes[key] = normalizeData(attributes[key]) - } + Object.keys(attributes) + .forEach((key) => { + attributes[key] = normalizeData(attributes[key]) + }) return attributes }, diff --git a/js/tests/unit/dom/manipulator.js b/js/tests/unit/dom/manipulator.js index 8a0be08ea..4b20529d4 100644 --- a/js/tests/unit/dom/manipulator.js +++ b/js/tests/unit/dom/manipulator.js @@ -41,16 +41,19 @@ $(function () { }) QUnit.test('should get data attributes', function (assert) { - assert.expect(2) + assert.expect(4) var $div = $('<div data-test="js" data-test2="js2" />').appendTo('#qunit-fixture') var $div2 = $('<div data-test3="js" data-test4="js2" />').appendTo('#qunit-fixture') + var $div3 = $('<div attri="1" />').appendTo('#qunit-fixture') assert.propEqual(Manipulator.getDataAttributes($div[0]), { test: 'js', test2: 'js2' }) + assert.propEqual(Manipulator.getDataAttributes(null), {}) + var stub = sinon .stub(Object, 'getOwnPropertyDescriptor') .callsFake(function () { @@ -62,6 +65,8 @@ $(function () { test4: 'js2' }) + assert.propEqual(Manipulator.getDataAttributes($div3[0]), {}) + stub.restore() }) |
