-
Notifications
You must be signed in to change notification settings - Fork 2
feat(native): Add toHaveTextContent matcher #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/native-to-have-style
Are you sure you want to change the base?
feat(native): Add toHaveTextContent matcher #153
Conversation
| return element.flatMap(child => this.collectText(child)); | ||
| } | ||
|
|
||
| if (element && typeof element === "object" && "props" in element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add parenthesis to group logical validations for a better readability please
| } | ||
|
|
||
| if (Array.isArray(element)) { | ||
| return element.flatMap(child => this.collectText(child)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure flatMap will always work here? is the collectText always going to return a 1-level nested array
| * @returns the assertion instance | ||
| */ | ||
| public toHaveTextContent(text: TestableTextMatcher): this { | ||
| const actualTextContent = this.getTextContent(this.actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.");| const error = new AssertionError({ | ||
| actual: this.actual, | ||
| message: `Expected element ${this.toString()} to have text content matching '` + | ||
| `${testableTextMatcherToString(text)}'.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use the text variable instead of the testableTextMatcherToString function for the messaging?
| * 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[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type naming for WithTextContext could improve for the readability to TextContent, wdyt?
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.