Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Apr 5, 2021
1 parent 9809d97 commit a77e32b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/expressions/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function removeAllAttributes(node, newAttributes, oldAttributes) {
* @returns {boolean} true if we can render this attribute value
*/
function canRenderAttribute(value) {
return value === true || typeof value === 'string'
return value === true || ['string', 'number'].includes(typeof value)
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/expressions/attribute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ describe('attribute specs', () => {
expect(p.selected).to.be.ok
})

it('number attributes will be rendered', () => {
const target = document.createElement('div')
template('<p expr0></p>', [{
selector: '[expr0]',
expressions: [
{ type: expressionTypes.ATTRIBUTE, name: 'class', evaluate: scope => scope.attr }
]
}]).mount(target, { attr: 1 })

const p = target.querySelector('p')

expect(p.getAttribute('class')).to.be.equal('1')
})

it('remove attribute if it\'s falsy', () => {
const target = document.createElement('div')
template('<p class="hello" expr0></p>', [{
Expand Down

0 comments on commit a77e32b

Please sign in to comment.