From a77e32b5b8e1f93252863513e1610956a4ca9bd0 Mon Sep 17 00:00:00 2001 From: gianlucaguarini Date: Mon, 5 Apr 2021 22:42:30 +0200 Subject: [PATCH] fixes https://github.com/riot/riot/issues/2902 --- src/expressions/attribute.js | 2 +- test/expressions/attribute.spec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/expressions/attribute.js b/src/expressions/attribute.js index 2b4ae5b..16b093e 100644 --- a/src/expressions/attribute.js +++ b/src/expressions/attribute.js @@ -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) } /** diff --git a/test/expressions/attribute.spec.js b/test/expressions/attribute.spec.js index 44f7996..8c12497 100644 --- a/test/expressions/attribute.spec.js +++ b/test/expressions/attribute.spec.js @@ -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('

', [{ + 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('

', [{