Skip to content

Instantly share code, notes, and snippets.

@craigcarlyle
Created August 3, 2018 18:45
Show Gist options
  • Save craigcarlyle/dffdf219fdc9f39f76d3ce40fc6bac7f to your computer and use it in GitHub Desktop.
Save craigcarlyle/dffdf219fdc9f39f76d3ce40fc6bac7f to your computer and use it in GitHub Desktop.
a11y Cypress KeyDown
const keycode = require("keycode");
Cypress.Commands.add("keyDown", (tagName: string, key: string, modifiers: Object) => {
return cy.window().then((win: any) => {
const event = Object.assign({
keyCode: keycode(key),
}, modifiers);
const e = win.$.Event("keydown", event);
win.$(tagName).trigger(e);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment