Skip to content

Conversation

kdquistanchala
Copy link
Contributor

This PR adds the toContainElement() matcher for React Native

@kdquistanchala kdquistanchala added the enhancement New feature or request label Mar 24, 2025
@kdquistanchala kdquistanchala self-assigned this Mar 24, 2025
.toHaveMessage("Expected element <View ... /> to contain element <Text ... />.");
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please add some tests for when there are no child nor parent elements 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the recommendation! To take this into account, I've changed the structure of the tests so they're clearer and easier to read 🚀

Copy link
Contributor

@suany0805 suany0805 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @kdquistanchala !

Copy link
Member

@JoseLion JoseLion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. I left a few comments. Let me know if you have any questions 🙂

}

return (
parentElement.findAll(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the .some() method instead of finding all elements and then checking if the length is > 0 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoseLion .some does not exist on ReactInstance class. It is not an array

Comment on lines +277 to +322
<View testID="grandParentId">
<View testID="parentId">
<View testID="childId" />
</View>
<Text testID="textId" />
</View>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use <Text> elements so that we can avoid the testIDs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im trying to do this, but im not getting good results, would you like to pair?

Comment on lines +275 to +316
describe (".toContainElement", () => {
const element = render(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a good practice, elements should be rendered on each test it(..) function, so the cleanup function cleans what's rendered before each test, avoid flaky tests, etc.

@kdquistanchala kdquistanchala force-pushed the feat/native-to-be-visible branch from 35e5052 to 82fa78b Compare April 25, 2025 18:41
@lopenchi lopenchi force-pushed the feat/native-to-contain-element branch 2 times, most recently from 1942629 to 4194055 Compare July 14, 2025 21:38
@lopenchi lopenchi force-pushed the feat/native-to-be-visible branch from 4cfe69c to dcded59 Compare July 14, 2025 21:42
@lopenchi lopenchi force-pushed the feat/native-to-contain-element branch from 4194055 to 392d9c6 Compare July 14, 2025 21:43
Base automatically changed from feat/native-to-be-visible to main July 22, 2025 21:38
@lopenchi lopenchi force-pushed the feat/native-to-contain-element branch from 560250d to a560a05 Compare July 22, 2025 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants