Created
August 3, 2018 18:45
-
-
Save craigcarlyle/dffdf219fdc9f39f76d3ce40fc6bac7f to your computer and use it in GitHub Desktop.
a11y Cypress KeyDown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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