Skip to content

Commit

Permalink
Render empty string on empty string as Trans child.
Browse files Browse the repository at this point in the history
Closes #363
  • Loading branch information
phiresky committed Dec 12, 2017
1 parent 7fd710d commit bf8ba38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Trans.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function nodesToString(mem, children, index) {
}

function renderNodes(children, targetString, i18n) {
if (targetString === "") return [];

// parse ast from string with additional wrapper tag
// -> avoids issues in parser removing prepending text nodes
Expand Down
11 changes: 11 additions & 0 deletions test/trans.render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@ describe('trans with t as prop', () => {
});

});

describe('trans with empty content', () => {
const TestElement = ({ t, cb }) => {
return <Trans>{""}</Trans>;
};
it('should render an empty string', () => {
const HocElement = translate(['translation'], {})(TestElement);
const wrapper = mount(<HocElement />, { context });
expect(wrapper.contains(<div></div>)).toBe(true);
});
});

0 comments on commit bf8ba38

Please sign in to comment.