Skip to content

Commit

Permalink
[RNMobile] Add optional custom editor component to native test helper (
Browse files Browse the repository at this point in the history
…#38133)

* Add optional custom editor component to helper

* Add config options into initialize editor helper

* Document the initialize editor test helper
  • Loading branch information
fluiddot authored Jan 21, 2022
1 parent 7628871 commit 433bd23
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/native/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ provideToNativeHtml.mockImplementation( ( html ) => {
serializedHtml = html;
} );

export function initializeEditor( props ) {
/**
* Initialize an editor for test assertions.
*
* @param {Object} props Properties passed to the editor component.
* @param {string} props.initialHtml String of block editor HTML to parse and render.
* @param {Object} [options] Configuration options for the editor.
* @param {import('react').ReactNode} [options.component] A specific editor component to render.
* @return {import('@testing-library/react-native').RenderAPI} A Testing Library screen.
*/
export function initializeEditor( props, { component = Editor } = {} ) {
// Portions of the React Native Animation API rely upon these APIs. However,
// Jest's 'legacy' fake timer mutate these globals, which breaks the Animated
// API. We preserve the original implementations to restore them later.
Expand All @@ -49,8 +58,9 @@ export function initializeEditor( props ) {
jest.useFakeTimers( 'legacy' );

// Arrange
const EditorComponent = component;
const screen = render(
<Editor
<EditorComponent
postId={ `post-id-${ uuid() }` }
postType="post"
initialTitle="test"
Expand Down

0 comments on commit 433bd23

Please sign in to comment.