diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index 04b9543c8a..faab54b5ef 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -43,16 +43,14 @@ const Manipulator = { return {} } - const attributes = { - ...element.dataset - } + const attributes = {} - Object.keys(attributes) + Object.keys(element.dataset) .filter(key => key.startsWith('bs')) .forEach(key => { let pureKey = key.replace(/^bs/, '') pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length) - attributes[pureKey] = normalizeData(attributes[key]) + attributes[pureKey] = normalizeData(element.dataset[key]) }) return attributes diff --git a/js/tests/unit/dom/manipulator.spec.js b/js/tests/unit/dom/manipulator.spec.js index 747e8bfd74..4f5ef715e8 100644 --- a/js/tests/unit/dom/manipulator.spec.js +++ b/js/tests/unit/dom/manipulator.spec.js @@ -60,32 +60,16 @@ describe('Manipulator', () => { expect().nothing() }) - it('should get all data attributes, without bs prefixed as well', () => { - fixtureEl.innerHTML = '
' + it('should get only bs prefixed data attributes without bs namespace', () => { + fixtureEl.innerHTML = '' const div = fixtureEl.querySelector('div') expect(Manipulator.getDataAttributes(div)).toEqual({ - bsToggle: 'tabs', - bsTarget: '#element', - another: 'value', toggle: 'tabs', target: '#element' }) }) - - it('should remove just prefixed bs keyword from the attributes and override original attribute with bs prefixed', () => { - fixtureEl.innerHTML = '' - - const div = fixtureEl.querySelector('div') - - expect(Manipulator.getDataAttributes(div)).toEqual({ - bsToggle: 'tabs', - targetBs: '#element', - inBsOut: 'in-between', - toggle: 'tabs' - }) - }) }) describe('getDataAttribute', () => {