UNPKG

slate-test-utils

Version:

> 📣 Love Slate and looking for your next gig? Sirona Medical is [hiring](https://sironamedical.com/about-us/careers/)!

73 lines (72 loc) • 2.76 kB
import { render } from '@testing-library/react'; import { Editor } from 'slate'; import { ComponentType } from 'react'; declare type ClipboardDataType = 'text/html' | 'text/plain' | 'image/png'; declare type PasteOptions = { types?: ClipboardDataType[]; }; export declare type RenderEditorReturnTuple = [ Editor, { type: (s: string) => Promise<void>; deleteForward: () => Promise<void>; deleteBackward: () => Promise<void>; deleteEntireSoftline: () => Promise<void>; deleteHardLineBackward: () => Promise<void>; deleteSoftLineBackward: () => Promise<void>; deleteHardLineForward: () => Promise<void>; deleteSoftLineForward: () => Promise<void>; deleteWordBackward: () => Promise<void>; deleteWordForward: () => Promise<void>; paste: (payload: string, options?: PasteOptions) => Promise<void>; pressEnter: () => Promise<void>; /** * Use a hotkey combination from is-hotkey. See testHarness internals * for usage. */ triggerKeyboardEvent: (hotkey: string) => Promise<void>; typeSpace: () => Promise<void>; undo: () => Promise<void>; redo: () => Promise<void>; selectAll: () => Promise<void>; isApple: () => boolean; rerender: () => void; }, ReturnType<typeof render> ]; /** * A test harness for the RichTextEditor that adds custom queries to assert on, lots * of simulated actions, and a custom rerender in case you want to assert on the DOM. * In most cases, you'll want to assert directly on the editor state to check that the editor * selection and other pieces of the editor are working as intended. */ export declare const buildTestHarness: (Component: ComponentType<any>) => ({ debug, strict, editor, componentProps, testID, }: { /** * A Slate editor singleton. */ editor: any; /** * Pretty logs out all operations on the editor so you can see what's going on in tests. */ debug?: boolean | undefined; /** * Ensures Slate content is valid before rendering. This is not turned on by default * because you may want to test invalid states for normalization or testing purposes. * * @default false */ strict?: boolean | undefined; /** * Props you would like to pass down to the element you have passed in to test. This could be disabled states * variants, specific styles, or anything else! */ componentProps?: any; /** * The test ID for the Editable component that is used * to run the test harness. * * @default 'slate-content-editable' */ testID?: string | undefined; }) => Promise<RenderEditorReturnTuple>; export {};