Skip to content
GitHubDiscord

prosekit/core/test

An editor for testing purposes.

get mounted(): boolean

Whether the editor is mounted.

get view(): EditorView

The editor view.

get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

The editor schema.

get state(): EditorState

The editor's current state.

get focused(): boolean

Whether the editor is focused.

get commands(): ExtractCommandActions<E>

All CommandActions defined by the editor.

get nodes(): ExtractNodeActions<E>

All NodeActions defined by the editor.

get marks(): ExtractMarkActions<E>

All MarkActions defined by the editor.

mount(place: undefined | null | HTMLElement): void

Mount the editor to the given HTML element. Pass null or undefined to unmount the editor.

unmount(): void

Unmount the editor. This is equivalent to mount(null).

focus(): void

Focus the editor.

blur(): void

Blur the editor.

use(extension: Extension): VoidFunction

Register an extension to the editor. Return a function to unregister the extension.

updateState(state: EditorState): void

Update the editor's state.

This is an advanced method. Use it only if you have a specific reason to directly manipulate the editor's state.

setContent(content: string | ProseMirrorNode | NodeJSON | HTMLElement, selection?: Selection | "start" | SelectionJSON | "end"): void

Update the editor's document and selection.

getDocJSON(): NodeJSON

Return a JSON object representing the editor's current document.

getDocHTML(options?: getDocHTMLOptions): string

Return a HTML string representing the editor's current document.

exec(command: Command): boolean

Execute the given command. Return true if the command was successfully executed, otherwise false.

canExec(command: Command): boolean

Check if the given command can be executed. Return true if the command can be executed, otherwise false.

set(doc: ProseMirrorNode): void

Set the editor state to the given document. You can use special tokens <a> and <b> to set the anchor and head positions of the selection.

const editor = createTestEditor({ extension })
const n = editor.nodes
const doc = n.doc(n.paragraph('<a>Hello<b> world!'))
editor.set(doc) // "Hello" is selected.

dispatchEvent(event: Event): void

function createTestEditor<E>(options: EditorOptions<E>): TestEditor<E>