Skip to content

Commit

Permalink
test: Fix Rich Text failures (#60290)
Browse files Browse the repository at this point in the history
* test: Define missing `logException` native module mock

Prevent cryptic test failure messages originating from invoking this
undefined method, which prevented the original error message from
surfacing in the test failure log.

* refactor: Export private API Rich Text module

This export was added for interoperability with the web version modified
in #58916.
  • Loading branch information
dcalhoun authored Mar 28, 2024
1 parent 2bf1dbd commit ec194db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,29 +655,32 @@ export function RichTextWrapper(
);
}

const ForwardedRichTextContainer = withDeprecations(
// This export does not actually implement a private API, but was exported
// under this name for interoperability with the web version of the RichText
// component.
export const PrivateRichText = withDeprecations(
forwardRef( RichTextWrapper )
);

ForwardedRichTextContainer.Content = Content;
PrivateRichText.Content = Content;

ForwardedRichTextContainer.isEmpty = ( value ) => {
PrivateRichText.isEmpty = ( value ) => {
return ! value || value.length === 0;
};

ForwardedRichTextContainer.Content.defaultProps = {
PrivateRichText.Content.defaultProps = {
format: 'string',
value: '',
};

ForwardedRichTextContainer.Raw = forwardRef( ( props, ref ) => (
PrivateRichText.Raw = forwardRef( ( props, ref ) => (
<RichText { ...props } nativeEditorRef={ ref } />
) );

/**
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
*/
export default ForwardedRichTextContainer;
export default PrivateRichText;
export { RichTextShortcut } from './shortcut';
export { RichTextToolbarButton } from './toolbar-button';
export { __unstableRichTextInputEvent } from './input-event';
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as globalStyles from './components/global-styles';
import { ExperimentalBlockEditorProvider } from './components/provider';
import { getRichTextValues } from './components/rich-text/get-rich-text-values';
import { lock } from './lock-unlock';
import { PrivateRichText } from './components/rich-text/';

/**
* Private @wordpress/block-editor APIs.
Expand All @@ -14,4 +15,5 @@ lock( privateApis, {
...globalStyles,
ExperimentalBlockEditorProvider,
getRichTextValues,
PrivateRichText,
} );
1 change: 1 addition & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jest.mock( '@wordpress/api-fetch', () => {
jest.mock( '@wordpress/react-native-bridge', () => {
return {
addEventListener: jest.fn(),
logException: jest.fn(),
mediaUploadSync: jest.fn(),
removeEventListener: jest.fn(),
requestBlockTypeImpressions: jest.fn( ( callback ) => {
Expand Down

0 comments on commit ec194db

Please sign in to comment.