feat: implement jest mock - #614
Open
eszlamczyk wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an official, importable Jest mock entrypoint for react-native-enriched-markdown so consumers can render and interact with EnrichedMarkdownTextInput / EnrichedMarkdownText under Jest without native Fabric/codegen crashes, and documents how to wire it up.
Changes:
- Introduces a Jest mock implementation (
src/jest) plus subpath shims (jest.js,jest.d.ts) to enablerequire('react-native-enriched-markdown/jest'). - Adds unit tests + Jest configuration and wires tests into CI.
- Adds testing documentation and a README link.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Locks new dev/test dependencies (Jest, RN Jest preset, test-renderer, etc.). |
| README.md | Adds a table-of-contents entry linking to the new Jest testing docs. |
| packages/react-native-enriched-markdown/tsconfig.json | Adds Jest types to support the new unit test setup. |
| packages/react-native-enriched-markdown/tsconfig.build.json | Excludes tests/Jest config from the build TS project. |
| packages/react-native-enriched-markdown/src/jest/index.tsx | Implements the Jest mock components and ref method spies. |
| packages/react-native-enriched-markdown/package.json | Adds Jest tooling deps and a test script; includes jest shims in published files. |
| packages/react-native-enriched-markdown/jest.js | Adds the runtime subpath entrypoint shim. |
| packages/react-native-enriched-markdown/jest.d.ts | Adds the TypeScript subpath entrypoint typings shim. |
| packages/react-native-enriched-markdown/jest.config.js | Adds a Jest config for the workspace’s unit tests. |
| packages/react-native-enriched-markdown/tests/jest-mock.test.tsx | Adds unit tests validating mock behavior and spy surface. |
| package.json | Adds a root yarn test that runs the workspace unit tests. |
| docs/TESTING.md | Documents how consumers should configure Jest to use/transform the mock. |
| .github/workflows/ci.yml | Runs unit tests in CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eszlamczyk
marked this pull request as ready for review
July 30, 2026 11:31
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.
What/Why?
Closes #576.
Ships an official, importable Jest mock so consumers can test screens that embed
EnrichedMarkdownTextInput/EnrichedMarkdownText. These are Fabric/codegen native components, so under Jest there is no native view manager and any imperative ref method (focus,setValue,toggleBold, ...) dispatches a native command and crashes. Today every consumer hand-rolls a mock that re-implements library internals (mirroring typed text to bothonChangeTextandonChangeMarkdown, suppressing emits for programmaticsetValue) and stubs thefull instance API, then has to keep it in sync with every release.
Consumers now wire it up once:
The mock:
TextInput(andTextfor the display component), so RNTL queries andfireEvent.changeTextwork out of the box;onChangeTextand, when a handler is set,onChangeMarkdownon input;setValue()update the rendered value while emitting no change events, matching the native suppression of emits for programmatic updates;jest.fn()spy, withgetMarkdown()resolving the current text andgetCaretRect()resolving a zero rect.The mock is authored in TS against the library's real public types (
EnrichedMarkdownTextInputProps,EnrichedMarkdownTextInputInstance,EnrichedMarkdownTextProps). If the component gains a prop or ref method the mock does not cover,yarn typecheckfails, so the mock cannot silently fall behind.Delivery note: the mock ships as compiled ESM, so consumers add the package to
transformIgnorePatterns(standard for RN libraries) -- documented indocs/TESTING.md.Testing
yarn test-- 6 new unit tests cover: rendering +defaultValue, event mirroring on input,setValueupdating the value without emitting, all imperative methods exposed as spies, async methods resolving sensible values, and the display component rendering its markdown.yarn typecheckandyarn lintpass.yarn prepare(bob build) produceslib/module/jest+ types; verified theEnrichedMarkdownTextInputInstancefailsyarn typecheckon the mock.Note: tests use
test-rendererdirectly rather than@testing-library/react-native; RNTL 14'srender()returns an empty object on this repo's React 19.2 / RN 0.85 toolchain (an environment incompatibility, not a mock issue). The docs still show the standard RNTL usage for consumers.PR Checklist