Skip to content

Commit

Permalink
fix: toHaveTextContent supports interpolated variables (testing-libra…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyshearer authored Aug 3, 2021
1 parent 408914b commit 1bd7419
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/__tests__/to-have-text-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ describe('.toHaveTextContent', () => {

expect(getByTestId('parent')).toHaveTextContent(/^Shown$/);
});

test('can handle text with an interpolated variable', () => {
const variable = 'variable';
const { container } = render(<Text>With a {variable}</Text>);

expect(container).toHaveTextContent('With a variable');
});
});
2 changes: 1 addition & 1 deletion src/to-have-text-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getText(child, currentValue = '') {
if (!child) {
return value;
} else if (Array.isArray(child)) {
return child.reduce((acc, element) => acc + getText(path(['props', 'children'], element)), '');
return child.reduce((acc, element) => acc + getText(element), '');
} else if (typeof child === 'object') {
return getText(path(['props', 'children'], child), value);
} else {
Expand Down

0 comments on commit 1bd7419

Please sign in to comment.