mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
Improve manipulator coverage
This commit is contained in:
parent
6cfc78f2d9
commit
57d50b2134
@ -63,13 +63,10 @@ const Manipulator = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key in attributes) {
|
Object.keys(attributes)
|
||||||
if (!Object.prototype.hasOwnProperty.call(attributes, key)) {
|
.forEach((key) => {
|
||||||
continue
|
attributes[key] = normalizeData(attributes[key])
|
||||||
}
|
})
|
||||||
|
|
||||||
attributes[key] = normalizeData(attributes[key])
|
|
||||||
}
|
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
},
|
},
|
||||||
|
@ -41,16 +41,19 @@ $(function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should get data attributes', function (assert) {
|
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 $div = $('<div data-test="js" data-test2="js2" />').appendTo('#qunit-fixture')
|
||||||
var $div2 = $('<div data-test3="js" data-test4="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]), {
|
assert.propEqual(Manipulator.getDataAttributes($div[0]), {
|
||||||
test: 'js',
|
test: 'js',
|
||||||
test2: 'js2'
|
test2: 'js2'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
assert.propEqual(Manipulator.getDataAttributes(null), {})
|
||||||
|
|
||||||
var stub = sinon
|
var stub = sinon
|
||||||
.stub(Object, 'getOwnPropertyDescriptor')
|
.stub(Object, 'getOwnPropertyDescriptor')
|
||||||
.callsFake(function () {
|
.callsFake(function () {
|
||||||
@ -62,6 +65,8 @@ $(function () {
|
|||||||
test4: 'js2'
|
test4: 'js2'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
assert.propEqual(Manipulator.getDataAttributes($div3[0]), {})
|
||||||
|
|
||||||
stub.restore()
|
stub.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user