diff --git a/packages/element/src/react-platform.native.js b/packages/element/src/react-platform.native.js new file mode 100644 index 0000000000000..4556ea0b845c0 --- /dev/null +++ b/packages/element/src/react-platform.native.js @@ -0,0 +1,14 @@ +/** + * External dependencies + */ +import { AppRegistry } from 'react-native'; + +/** + * Registers an app root component allowing the native system to run the app. + * + * @param {string} appKey Unique app name identifier. + * @param {Function} componentProvider Function returning the app root React component. + */ +export const registerComponent = ( appKey, componentProvider ) => { + AppRegistry.registerComponent( appKey, componentProvider ); +}; diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index cb3128ea5cf7c..85ba6915e9447 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -2,13 +2,12 @@ * External dependencies */ import 'react-native-gesture-handler'; -import { AppRegistry } from 'react-native'; /** * WordPress dependencies */ import { applyFilters, doAction } from '@wordpress/hooks'; -import { Component, cloneElement } from '@wordpress/element'; +import { Component, cloneElement, registerComponent } from '@wordpress/element'; /** * Internal dependencies @@ -77,7 +76,7 @@ const registerGutenberg = ( { } } - AppRegistry.registerComponent( 'gutenberg', () => Gutenberg ); + registerComponent( 'gutenberg', () => Gutenberg ); }; export { initialHtml as initialHtmlGutenberg, registerGutenberg, setupLocale }; diff --git a/packages/react-native-editor/src/test/index.test.js b/packages/react-native-editor/src/test/index.test.js index c734603279ea4..223f4247a4069 100644 --- a/packages/react-native-editor/src/test/index.test.js +++ b/packages/react-native-editor/src/test/index.test.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { AppRegistry } from 'react-native'; +import { AppRegistry, Text } from 'react-native'; import { render, waitFor } from 'test/helpers'; /** @@ -176,9 +176,19 @@ describe( 'Register Gutenberg', () => { expect( hookCallOrder ).toBeGreaterThan( onRenderEditorCallOrder ); } ); - it( 'initializes the editor', () => { - const { getByTestId } = initGutenberg(); - const blockList = waitFor( () => getByTestId( 'block-list-wrapper' ) ); + it( 'initializes the editor', async () => { + const MockEditor = () => Mock Editor; + jest.mock( '../setup', () => { + return { + __esModule: true, + default: jest.fn( () => ), + }; + } ); + + const screen = initGutenberg(); + const blockList = await waitFor( () => + screen.getByText( 'Mock Editor' ) + ); expect( blockList ).toBeDefined(); } ); } );