feat(jest): support onLinkPress, onLinkLongPress, and onTaskListItemPress in mock - #712
Merged
hryhoriiK97 merged 2 commits intoAug 26, 2026
Conversation
…ress in mock
The Jest mock for EnrichedMarkdownText previously discarded all interaction
callbacks, rendering markdown as a flat string. This made it impossible to
test link press handlers or task list interactions without per-file mock
overrides.
This change adds a composable transform pipeline that:
- Parses [text](url) patterns into pressable <Text accessibilityRole="link">
elements that fire onLinkPress/onLinkLongPress with { url }
- Parses GFM task list items (- [x] / - [ ]) into pressable checkbox elements
that fire onTaskListItemPress with { index, checked, text }
- Strips inline formatting markers from link display text
- Only activates transforms when their callbacks are provided (zero overhead
when not used, backward-compatible)
The architecture uses a shared splitByPattern utility so adding future
transforms (e.g. bold rendering, mentions) requires only a small factory
function.
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the Jest mock for EnrichedMarkdownText so tests can exercise interaction callbacks (link press/long-press and task list item toggles) instead of treating markdown as a flat string.
Changes:
- Added a small transform pipeline in the Jest mock to turn link/task-list syntax into pressable React Native
<Text>children. - Added link and task-list interaction test cases for the mock behavior.
- Added basic inline-formatting stripping for link display text in the mock.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/react-native-enriched-markdown/src/jest/index.tsx | Adds transform utilities and renders links/task items as pressable elements in the Jest mock. |
| packages/react-native-enriched-markdown/tests/jest-mock.test.tsx | Adds test coverage for link and task-list interactions in the mock. |
Suppressed comments (2)
packages/react-native-enriched-markdown/src/jest/index.tsx:335
- Task list interaction is documented as GitHub-flavor-only (
src/types/MarkdownTextProps.ts:161-162). The Jest mock currently enables task-list parsing wheneveronTaskListItemPressis provided, regardless offlavor(the mock destructuresflavorbut doesn’t use it). This can make Jest tests pass while the real component (defaultflavor='commonmark') would never emit task events. Consider plumbingflavorintobuildChildrenand only enabling the task-list transform whenflavor === 'github'.
{buildChildren(markdown, {
onLinkPress,
onLinkLongPress,
onTaskListItemPress,
})}
packages/react-native-enriched-markdown/tests/jest-mock.test.tsx:258
- This task-list test also relies on task lists without setting
flavor="github", even though the API contract specifies task-list events only in GitHub flavor. Addingflavor="github"keeps the test representative of real usage.
<EnrichedMarkdownText
testID="display"
markdown={'- [ ] First task\n- [x] Second task'}
onTaskListItemPress={onTaskListItemPress}
/>
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
… tests - Reorder transforms so task-list runs first, preventing link parsing from splitting task lines before TASK_ITEM_RE can match - Add flavor="github" to task list tests to align with public contract Co-authored-by: Cursor <cursoragent@cursor.com>
eszlamczyk
approved these changes
Aug 26, 2026
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.
Summary
The Jest mock for
EnrichedMarkdownTextcurrently discards all interaction callbacks (onLinkPress,onLinkLongPress,onTaskListItemPress), rendering markdown as a flat string. This forces consumers to write per-file mock overrides just to test link press handlers or task list interactions.This PR adds a composable transform pipeline to the mock that:
[text](url)into pressable<Text accessibilityRole="link">elements that fireonLinkPress/onLinkLongPresswith{ url }- [x]/- [ ]) into pressable checkbox elements that fireonTaskListItemPresswith{ index, checked, text }**,*,__,_markers from link display text so queries match visible contentArchitecture
A shared
splitByPattern(segment, regex, renderMatch)utility handles the iteration boilerplate. Each feature is a small factory function (createLinkTransform,createTaskListTransform) that returns aTransformFn. Adding future features (e.g. bold rendering, mentions) requires only appending a new factory to thebuildChildrenarray.Test plan
__tests__/jest-mock.test.tsxcovering:accessibilityRole="link"onLinkPresscallback with{ url }onLinkLongPresscallback with{ url }accessibilityStateonTaskListItemPresswith toggled stateyarn test)yarn typecheck)Made with Cursor