Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/byText.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ test.skip('getByText works properly with custom text container', () => {
).toBeTruthy();
});

test('getByText works properly with React.Fragment nested in <Text>', () => {
function FragmentText({ children }) {
return <React.Fragment>{children}</React.Fragment>;
}

const { getByText, queryByText } = render(
<Text>
<FragmentText>Hello</FragmentText>
</Text>
);
expect(getByText('Hello')).toBeTruthy();
expect(queryByText('Hello')).not.toBeNull();
});

test('queryByText nested <Image> in <Text> at start', () => {
expect(
render(
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/byText.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ const getNodeByText = (
return matches(text, textToTest, normalizer, exact);
}
}
if (node?.parent?.parent) {
const isParentTextComponent = filterNodeByType(node.parent?.parent, Text);
if (isParentTextComponent && !isTextComponent) {
if (typeof node.children?.[0] === 'string') {
const textToTest = node.children.join('');
return typeof text === 'string'
? text === textToTest
: text.test(textToTest);
}
}
}

return false;
} catch (error) {
throw createLibraryNotSupportedError(error);
Expand Down