Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

How to simulate user input for testing purpose? #347

Closed
llh1 opened this issue Apr 29, 2016 · 2 comments
Closed

How to simulate user input for testing purpose? #347

llh1 opened this issue Apr 29, 2016 · 2 comments

Comments

@llh1
Copy link

llh1 commented Apr 29, 2016

Hi all,

First, thanks for providing such a great library.

Actually, this is more a question than an issue. We are trying to write tests including the rich text editor that we built using DraftJS. Our rich text editor is part of a bigger form (written with React) that we need to test. One of the problem that we faced is we don't know how to simulate a text input into our editor. Ideally, we would like to use the React TestUtils.Simulate function.

Any advice on how to proceed? Which event to we need to simulate on which DOM node?

Thanks!

@llh1
Copy link
Author

llh1 commented Apr 29, 2016

Well, I've finally found the answer to my question debugging Draft.
So here is the solution if anybody needs it. You need to target the dom node with the class name public-DraftEditor-content and trigger a beforeInputevent.

With React TestUtils:

var draftEditorContent = TestUtils.findRenderedDOMComponentWithClass("public-DraftEditor-content");
TestUtils.Simulate.beforeInput(draftEditorContent, {data: "some text"});

@danawoodman
Copy link

For future readers; beforeInput no longer exists so this won't work anymore

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants