aboutsummaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/tests/queries/dom.ts
blob: e1515c8b4ecc1148b453edd6c4f0ffbb8c94f486 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { waitFor } from "@testing-library/dom";
import { fireEvent } from "@testing-library/react";

export const getTextEditor = async (selector: string, waitForEditor = true) => {
  const query = () => document.querySelector(selector) as HTMLTextAreaElement;
  if (waitForEditor) {
    await waitFor(() => expect(query()).not.toBe(null));
    return query();
  }
  return query();
};

export const updateTextEditor = (
  editor: HTMLTextAreaElement | HTMLInputElement,
  value: string,
) => {
  fireEvent.change(editor, { target: { value } });
  fireEvent.input(editor);
};