Browse Source

modify component.toHTML() to include attributes with empty-string values

pull/550/head
Ryan Deba 9 years ago
parent
commit
4a1763cc08
  1. 2
      src/dom_components/model/Component.js
  2. 10
      test/specs/dom_components/model/Component.js

2
src/dom_components/model/Component.js

@ -554,7 +554,7 @@ module.exports = Backbone.Model.extend(Styleable).extend({
for (let attr in attributes) {
const value = attributes[attr];
if (!isUndefined(value) && value !== '') {
if (!isUndefined(value)) {
attrs.push(`${attr}="${value}"`);
}
}

10
test/specs/dom_components/model/Component.js

@ -82,6 +82,16 @@ module.exports = {
expect(obj.toHTML()).toEqual('<article data-test1="value1" data-test2="value2"></article>');
});
it('Component toHTML with value-less attribute', () => {
obj = new Component({
tagName: 'div',
attributes: {
'data-is-a-test': ''
}
});
expect(obj.toHTML()).toEqual('<div data-is-a-test=""></div>');
});
it('Component toHTML with classes', () => {
obj = new Component({
tagName: 'article'

Loading…
Cancel
Save