mwood23 / slate-test-utils

A toolkit to test Slate rich text editors with Jest, React Testing Library, and hyperscript! Write user driven integration tests with ease.
MIT License
57 stars 6 forks source link

Add support for new paste function #4

Closed hanford closed 2 years ago

hanford commented 2 years ago

This PR adds support for broadcasting paste events that slate-react properly receives and handles to various insertData functions.

My test looks like this:

import { assertOutput, buildTestHarness } from 'slate-test-utils';
import { jsx as h } from 'slate-hyperscript';

import TextEditor from '..';

it('user copy and pastes link', async () => {
  const input = h('editor', [h('element', { type: 'paragraph' }, [h('text', [h('cursor')])])]);

  const [editor, { paste }] = await buildTestHarness(TextEditor)({
    editor: input,
  });

  await paste('foo!');

  assertOutput(
    editor,
    h('editor', [h('element', { type: 'paragraph' }, [h('text', ['foo!', h('cursor')])])]),
  );
});

image

hanford commented 2 years ago

Added an optional option argument that will allow consumers to change the types value. Let me know if there is anything else!