Skip to content

Commit 2767b49

Browse files
committed
fix: toHaveTextContent supports interpolated variables
1 parent 3cfd279 commit 2767b49

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/__tests__/to-have-text-content.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,11 @@ describe('.toHaveTextContent', () => {
9696

9797
expect(getByTestId('parent')).toHaveTextContent(/^Shown$/);
9898
});
99+
100+
test('can handle text with an interpolated variable', () => {
101+
const variable = 'variable';
102+
const { container } = render(<Text>With a {variable}</Text>);
103+
104+
expect(container).toHaveTextContent('With a variable');
105+
});
99106
});

src/to-have-text-content.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { matcherHint } from 'jest-matcher-utils';
2-
import { compose, defaultTo, is, join, map, path, filter } from 'ramda';
2+
import { compose, defaultTo, is, join, map, path, filter, pathOr } from 'ramda';
33

44
import { checkReactElement, getMessage, matches, normalize } from './utils';
55

@@ -9,7 +9,7 @@ function getText(child, currentValue = '') {
99
if (!child) {
1010
return value;
1111
} else if (Array.isArray(child)) {
12-
return child.reduce((acc, element) => acc + getText(path(['props', 'children'], element)), '');
12+
return child.reduce((acc, element) => acc + getText(element), '');
1313
} else if (typeof child === 'object') {
1414
return getText(path(['props', 'children'], child), value);
1515
} else {

0 commit comments

Comments
 (0)