Skip to content

Any way to programatically give key input events? #830

@oatymart

Description

@oatymart

I'm trying to set up an end-to-end test using Cypress. I can already render a Mathfield and simulate some user input to it by triggering clicks on virtual keyboard buttons.

What I'd like to do now is simulate user keypresses. Taking Cypress out of the equation for a moment, here's my non-working code executed in the browser console.

let elt = $('math-field'); // ok
elt.focus(); // ok, document.activeElement changed
document.dispatchEvent(new KeyboardEvent('keydown', { key:'e', keyCode: 69 }));
document.dispatchEvent(new KeyboardEvent('keyup', { key:'e', keyCode: 69 })); // nada

Am I sending wrong events or targeting the wrong element? Is this possible to do, or should I just use the elt.setValue() method, even if my users won't use that?

Metadata

Metadata

Assignees

Labels

featureRequest for a new feature or functionality, as opposed to a defect in an existing feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions