@ember/test-helpers
Version:
Helpers for testing Ember.js applications
42 lines (40 loc) • 2.58 kB
TypeScript
import { type KeyboardEventType } from './fire-event.ts';
import type { Target } from './-target.ts';
export interface KeyModifiers {
ctrlKey?: boolean;
altKey?: boolean;
shiftKey?: boolean;
metaKey?: boolean;
}
/**
@private
@param {Element | Document} element the element to trigger the key event on
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
@param {Object} [modifiers] the state of various modifier keys
@return {Promise<Event>} resolves when settled
*/
export declare function __triggerKeyEvent__(element: Element | Document, eventType: KeyboardEventType, key: number | string, modifiers?: KeyModifiers): Promise<Event>;
/**
Triggers a keyboard event of given type in the target element.
It also requires the developer to provide either a string with the [`key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
or the numeric [`keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) of the pressed key.
Optionally the user can also provide a POJO with extra modifiers for the event.
@public
@param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to trigger the event on
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
@param {Object} [modifiers] the state of various modifier keys
@param {boolean} [modifiers.ctrlKey=false] if true the generated event will indicate the control key was pressed during the key event
@param {boolean} [modifiers.altKey=false] if true the generated event will indicate the alt key was pressed during the key event
@param {boolean} [modifiers.shiftKey=false] if true the generated event will indicate the shift key was pressed during the key event
@param {boolean} [modifiers.metaKey=false] if true the generated event will indicate the meta key was pressed during the key event
@return {Promise<void>} resolves when the application is settled unless awaitSettled is false
@example
<caption>
Emulating pressing the `ENTER` key on a button using `triggerKeyEvent`
</caption>
triggerKeyEvent('button', 'keydown', 'Enter');
*/
export default function triggerKeyEvent(target: Target, eventType: KeyboardEventType, key: number | string, modifiers?: KeyModifiers): Promise<void>;
//# sourceMappingURL=trigger-key-event.d.ts.map