Skip to content

feat: implement jest mock - #614

Open
eszlamczyk wants to merge 3 commits into
mainfrom
feat/576/jest-mock
Open

feat: implement jest mock#614
eszlamczyk wants to merge 3 commits into
mainfrom
feat/576/jest-mock

Conversation

@eszlamczyk

@eszlamczyk eszlamczyk commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

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 both onChangeText and onChangeMarkdown, suppressing emits for programmatic setValue) and stubs the
full instance API, then has to keep it in sync with every release.

Consumers now wire it up once:

// jest.setup.js
jest.mock('react-native-enriched-markdown', () =>
  require('react-native-enriched-markdown/jest'),
);

The mock:

  • renders a plain RN TextInput (and Text for the display component), so RNTL queries and fireEvent.changeText work out of the box;
  • emits onChangeText and, when a handler is set, onChangeMarkdown on input;
  • makes setValue() update the rendered value while emitting no change events, matching the native suppression of emits for programmatic updates;
  • exposes every imperative method as a jest.fn() spy, with getMarkdown() resolving the current text and getCaretRect() 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 typecheck fails, 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 in docs/TESTING.md.

Testing

  • yarn test -- 6 new unit tests cover: rendering + defaultValue, event mirroring on input, setValue updating the value without emitting, all imperative methods exposed as spies, async methods resolving sensible values, and the display component rendering its markdown.
  • yarn typecheck and yarn lint pass.
  • yarn prepare (bob build) produces lib/module/jest + types; verified the
    `require('react-native-enriched-markdown/jest')` -> root shim -> compiled mock 
    
    resolution chain works under Jest.
  • Verified the drift guard trips: temporarily adding a method to EnrichedMarkdownTextInputInstance fails yarn typecheck on the mock.

Note: tests use test-renderer directly rather than @testing-library/react-native; RNTL 14's render() 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

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes
  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 enable require('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.

Comment thread packages/react-native-enriched-markdown/src/jest/index.tsx Outdated
Comment thread packages/react-native-enriched-markdown/src/jest/index.tsx Outdated
@eszlamczyk
eszlamczyk requested a review from hryhoriiK97 July 30, 2026 11:31
@eszlamczyk
eszlamczyk marked this pull request as ready for review July 30, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an official Jest mock for EnrichedMarkdownTextInput

2 participants