Skip to content

Commit

Permalink
Improve manipulator coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Feb 20, 2019
1 parent 6cfc78f commit 57d50b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 4 additions & 7 deletions js/src/dom/manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
7 changes: 6 additions & 1 deletion js/tests/unit/dom/manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -62,6 +65,8 @@ $(function () {
test4: 'js2'
})

assert.propEqual(Manipulator.getDataAttributes($div3[0]), {})

stub.restore()
})

Expand Down

0 comments on commit 57d50b2

Please sign in to comment.