From 0270f3a7a84b1e7d93ccd944a098df07306b4214 Mon Sep 17 00:00:00 2001 From: simonguo Date: Mon, 7 May 2018 16:31:21 +0800 Subject: [PATCH] Bugfix: return value mismatch when parameter is 0 --- src/utils/tplTransform.js | 2 +- test/utilsSpec.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/tplTransform.js b/src/utils/tplTransform.js index 2be7e53827..be30f4a266 100644 --- a/src/utils/tplTransform.js +++ b/src/utils/tplTransform.js @@ -2,7 +2,7 @@ import * as React from 'react'; -const toJSX = (node, key) => (node ? {node} : null); +const toJSX = (node, key) => (typeof node !== 'undefined' ? {node} : null); /** * tplTransform('Show {0} data', 100); diff --git a/test/utilsSpec.js b/test/utilsSpec.js index 045f0aa03f..aa309d63d4 100644 --- a/test/utilsSpec.js +++ b/test/utilsSpec.js @@ -9,9 +9,15 @@ describe('[utils] tplTransform', () => { const str = '{1}Show {0} data {1}, {0}'; const nodes = tplTransform(str, 30, 10); const instance = ReactTestUtils.renderIntoDocument(
{nodes}
); - assert.equal(instance.innerText, '10Show 30 data 10, 30'); }); + + it('Should return match value when parameter is 0', () => { + const str = '共 {0} 条数据'; + const nodes = tplTransform(str, 0); + const instance = ReactTestUtils.renderIntoDocument(
{nodes}
); + assert.equal(instance.innerText, '共 0 条数据'); + }); }); describe('[utils] isOneOf', () => {