feat(native): Add toHaveTextContent matcher#153
Draft
ACR1209 wants to merge 3 commits intofeat/native-to-have-stylefrom
Draft
feat(native): Add toHaveTextContent matcher#153ACR1209 wants to merge 3 commits intofeat/native-to-have-stylefrom
ACR1209 wants to merge 3 commits intofeat/native-to-have-stylefrom
Conversation
SbsCruz
reviewed
Oct 28, 2025
| return element.flatMap(child => this.collectText(child)); | ||
| } | ||
|
|
||
| if (element && typeof element === "object" && "props" in element) { |
Contributor
There was a problem hiding this comment.
could you add parenthesis to group logical validations for a better readability please
SbsCruz
reviewed
Oct 28, 2025
| } | ||
|
|
||
| if (Array.isArray(element)) { | ||
| return element.flatMap(child => this.collectText(child)); |
Contributor
There was a problem hiding this comment.
are we sure flatMap will always work here? is the collectText always going to return a 1-level nested array
SbsCruz
reviewed
Oct 28, 2025
| * @returns the assertion instance | ||
| */ | ||
| public toHaveTextContent(text: TestableTextMatcher): this { | ||
| const actualTextContent = this.getTextContent(this.actual); |
Contributor
There was a problem hiding this comment.
we could validate that text is a string, RegExp, or function before this line so we can throw the error from helpers/testableTextMatcherToString here:
throw new Error("Matcher must be a string, RegExp, or function.");
SbsCruz
reviewed
Oct 28, 2025
| const error = new AssertionError({ | ||
| actual: this.actual, | ||
| message: `Expected element ${this.toString()} to have text content matching '` + | ||
| `${testableTextMatcherToString(text)}'.`, |
Contributor
There was a problem hiding this comment.
could we use the text variable instead of the testableTextMatcherToString function for the messaging?
SbsCruz
reviewed
Oct 28, 2025
| * Type representing a value that can be used to match text content in tests. | ||
| * It can be a string, a ReactTestInstance, or an array of ReactTestInstances. | ||
| */ | ||
| export type WithTextContent = string | ReactTestInstance | ReactTestInstance[]; |
Contributor
There was a problem hiding this comment.
type naming for WithTextContext could improve for the readability to TextContent, wdyt?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
toHaveTextContentmatcher to the React Native module, allowing you to match an element’s text content using a string, a regular expression, or a custom function.