Skip to content

Commit

Permalink
don't error on falsy placeholder values, fixes jenseng#11
Browse files Browse the repository at this point in the history
  • Loading branch information
jenseng committed May 9, 2015
1 parent b9d5489 commit e86cb82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ComponentInterpolator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
`<ComponentInterpolator> expected '${token}' placeholder value, none found`
);
child = this.props[token];
child = child.type ? cloneWithProps(child, {key: tokens.length}) : child;
children.push(child);
} else {
Expand Down
5 changes: 3 additions & 2 deletions __tests__/ComponentInterpolator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <input />
}, ["$1"]);
expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual(
'Hi Jane, create <input> new accounts'
'Hi Jane (0), create <input> new accounts'
);
});
});

0 comments on commit e86cb82

Please sign in to comment.