Simulating user input


I am about to create automated tests for a React component which is a wrapper around ProseMirror.

I would like to simulate the user input, and test whether my change handler has run and pm.getContent(‘text’) is equal to the input.

In the simplest case, I have an empty document with doc format set to ‘text’. I want to insert a single character (character C in the example) and want both of the above requirements met.

In my first test, I am calling Pos([0], 0), 'C').apply()

which successfully triggers the change handler, but when I call


, it returns the empty string. Instead of the excepted ‘C’.

In the doc, I have read about pm.flush(), however calling it right after insertText does not effect the outcome.

Seems to me that my expectations are just not right about getContent() and flush(), but how could you then go about simulating user input properly?

With thanks, Laszlo

What you’re doing should work. See if there’s something else about your test setup that’s causing confusion.

Thanks, yes indeed, I’ve just tested it without React, and it works as excepted.