Replies: 9 comments 3 replies
-
|
I am also running into issues like these when testing components that involve lexical. Some guidance here would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
I am also experiencing this problem. When I tried to test the type event: const contentEditable = screen.getByRole('textbox')
await user.click(contentEditable)
await user.type(contentEditable, 'test')
screen.debug(contentEditable)or with keyboard events: const contentEditable = screen.getByRole('textbox')
await user.click(contentEditable)
await user.keyboard('test')
screen.debug(contentEditable)The result of the debug function was: <div
contenteditable="true"
data-lexical-editor="true"
role="textbox"
spellcheck="true"
style="user-select: text; white-space: pre-wrap; word-break: break-word;"
>
<p>
<br />
</p>
</div>I tried adding an event listener to the contentEditable to see what was going on under the hood. contentEditable.addEventListener('input', () => {
console.log(contentEditable.textContent)
})I noticed that the console log is called on every keypress, but nothing is generated inside the contentEditable. |
Beta Was this translation helpful? Give feedback.
-
|
I'm not sure if this question is targeting headless only, but I've been using playwright for point and click testing without any issues, but for an editor instance that has UI. I haven't seen the repo using Cypress, maybe I started looking at the code at a much later stage. Have a go with Playwright. |
Beta Was this translation helpful? Give feedback.
-
|
Facing this as well, tried I console logged in the Currently circumventing this with playwright tests, though being able to write unit tests would be nice :/ |
Beta Was this translation helpful? Give feedback.
-
|
Opened an issue for this here: #4595 @doytch I'm using your description here, it's really detailed! |
Beta Was this translation helpful? Give feedback.
-
|
Is there anything new about the above? |
Beta Was this translation helpful? Give feedback.
-
|
I was able to resolve the issue above by using user-event + fireEvent const editor = await screen.findByRole('textbox', { name: 'Content' });
await user.click(editor);
await user.tab();
fireEvent.input(editor, { data: 'test' });after using |
Beta Was this translation helpful? Give feedback.
-
|
We've been using the experimental playwright component testing system after too many issues with JS DOM. It has been fairly seamless to use. As these run in actual browsers we haven't had to jump through any JS Dom hoops. Playwright has been extremely consistent without the usual integration test flakeyness. All of the lexical playground specs are written for playwright and we have gotten most of them converted over (with some minor tweaks) to the playwright component testing system fairly easily. Then layered in our own specs for our customizations. |
Beta Was this translation helpful? Give feedback.
-
|
JSDOM still doesn't support contenteditable jsdom/jsdom#1670 |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks, I've been building out an editor using Lexical for the past couple of days and one thing I'm still quite hazy on is testing.
I've created a new component - let's call it

RichTextEditor- that renders aLexicalComposeralong with a customEmailAddressPlugin. Said plugin has a decoratorEmailAddressNodewhich tokenizes the email strings like so:Nothing super fancy, think the tokenizing in most email clients' composer's "To" fields.
I'd like to be able to write some tests to verify the functionality from the user's perspective. Eg, select the textarea, press keyboard keys, verify the DOM.
I'm using Remix + Vitest + RTL and quickly ran into issues where it seems like something's not being picked up properly.
The output of
screen.debug()(an RTL helper) included the following:That output (the
pandbrespecially) suggests to me that thecontenteditableis being focused but the keyboard events aren't being registered properly. If I snoop a bit using theOnChangePlugin, then I can see the onChange is firing four times but there isn't anything in theSerializedEditorStatebesides thatpandbreither.Question 1: Before I keep digging more into this, is this a known issue with
jsdomor other headless engines (happy-dom?)? I noticed that the project uses Cypress and I'm wondering whether that's because the tests I want to write are simply not possible with headless unit tests like I'm using.Question 2: If I am up a creek writing these kinds of unit tests, what's the suggested way of testing custom nodes and plugins? I know there are a bunch of unit tests in the codebase for the builtin nodes/plugins but given the
0.x.ynature of the project I'm wary about drawing toooo many conclusions (especially after I went down aninertrabbit hole before reading a PR deprecating it 😅). Are there any exemplars I could pattern my tests off of? If it doesn't exist yet, I'd love to take this as an opportunity to build a "So you want to test your custom node/plugin?" doc.Beta Was this translation helpful? Give feedback.
All reactions