From 82eef529bbfe3c3a5356c581dc38d0d4f0b1f5ef Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:04:57 +0100 Subject: [PATCH] add mock --- mock/index.ts | 14 ++++++++++++++ package.json | 1 + src/MarkdownTextInput.tsx | 5 ++--- tsconfig.json | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 mock/index.ts diff --git a/mock/index.ts b/mock/index.ts new file mode 100644 index 00000000..6e082dea --- /dev/null +++ b/mock/index.ts @@ -0,0 +1,14 @@ +import {MarkdownTextInput} from '../src'; +import type {parseExpensiMark} from '../src'; + +global.jsi_setMarkdownRuntime = jest.fn(); +global.jsi_registerMarkdownWorklet = jest.fn(); +global.jsi_unregisterMarkdownWorklet = jest.fn(); + +const parseExpensiMarkMock: typeof parseExpensiMark = () => { + 'worklet'; + + return []; +}; + +export {MarkdownTextInput, parseExpensiMarkMock as parseExpensiMark}; diff --git a/package.json b/package.json index 9d3243de..e28bddd6 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "files": [ "src", "lib", + "mock", "android", "apple", "cpp", diff --git a/src/MarkdownTextInput.tsx b/src/MarkdownTextInput.tsx index c4ec2467..b744a9bd 100644 --- a/src/MarkdownTextInput.tsx +++ b/src/MarkdownTextInput.tsx @@ -28,10 +28,9 @@ function initializeLiveMarkdownIfNeeded() { if (initialized) { return; } - if (!NativeLiveMarkdownModule) { - throw new Error('[react-native-live-markdown] NativeLiveMarkdownModule is not available'); + if (NativeLiveMarkdownModule) { + NativeLiveMarkdownModule.install(); } - NativeLiveMarkdownModule.install(); if (!global.jsi_setMarkdownRuntime) { throw new Error('[react-native-live-markdown] global.jsi_setMarkdownRuntime is not available'); } diff --git a/tsconfig.json b/tsconfig.json index 5af82eae..a92fd85d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,6 @@ "verbatimModuleSyntax": true, "typeRoots": ["node_modules/@types"] }, - "include": ["src/**/*"], + "include": ["src/**/*", "mock/**/*"], "exclude": ["**/node_modules/**/*", "**/lib/**/*", "example/src/**/*", "WebExample/**/*"] }