From e86cb8220816bef4ee3108784a4f9d9c6ca392ec Mon Sep 17 00:00:00 2001 From: Jon Jensen Date: Fri, 8 May 2015 20:51:48 -0600 Subject: [PATCH] don't error on falsy placeholder values, fixes #11 --- ComponentInterpolator.js | 3 ++- __tests__/ComponentInterpolator.test.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ComponentInterpolator.js b/ComponentInterpolator.js index e5426f3..0134480 100644 --- a/ComponentInterpolator.js +++ b/ComponentInterpolator.js @@ -103,9 +103,10 @@ var ComponentInterpolator = React.createClass({ if (token.match(PLACEHOLDER_PATTERN)) { token = token.slice(2, -1); invariant( - child = this.props[token], + this.props.hasOwnProperty(token), ` expected '${token}' placeholder value, none found` ); + child = this.props[token]; child = child.type ? cloneWithProps(child, {key: tokens.length}) : child; children.push(child); } else { diff --git a/__tests__/ComponentInterpolator.test.js b/__tests__/ComponentInterpolator.test.js index 25816fe..79476b4 100644 --- a/__tests__/ComponentInterpolator.test.js +++ b/__tests__/ComponentInterpolator.test.js @@ -41,13 +41,14 @@ describe('ComponentInterpolator', function() { it('interpolates placeholder components', function() { var subject = Subject({ - string: 'Hi %{user}, create %{count} new accounts', + string: 'Hi %{user} (%{user_id}), create %{count} new accounts', wrappers: {}, user: "Jane", + user_id: 0, count: }, ["$1"]); expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual( - 'Hi Jane, create new accounts' + 'Hi Jane (0), create new accounts' ); }); });