Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function triggerEvent(
target: Target,
eventType: string,
options?: object
): Promise {
log('triggerEvent', target, eventType);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `triggerEvent`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`triggerEvent('${target}', ...)\`.`);
}
if (!eventType) {
throw new Error(`Must provide an \`eventType\` to \`triggerEvent\``);
}
fireEvent(element, eventType, options);
export default function doubleClick(target: Target, options: MouseEventInit = {}): Promise {
log('doubleClick', target);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `doubleClick`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`doubleClick('${target}')\`.`);
}
__doubleClick__(element, options);
return settled();
});
}
export default function fillIn(target: Target, text: string): Promise {
log('fillIn', target, text);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `fillIn`.');
}
let element = getElement(target) as any;
if (!element) {
throw new Error(`Element not found when calling \`fillIn('${target}')\`.`);
}
let isControl = isFormControl(element);
if (!isControl && !element.isContentEditable) {
throw new Error('`fillIn` is only usable on form controls or contenteditable elements.');
}
if (typeof text === 'undefined' || text === null) {
export default function click(target: Target, options: MouseEventInit = {}): Promise {
log('click', target);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `click`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`click('${target}')\`.`);
}
let isDisabledFormControl = isFormControl(element) && element.disabled;
if (!isDisabledFormControl) {
__click__(element, options);
}
export default function triggerKeyEvent(
target: Target,
eventType: KeyboardEventType,
key: number | string,
modifiers: KeyModifiers = DEFAULT_MODIFIERS
): Promise {
log('triggerKeyEvent', target, eventType, key);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `triggerKeyEvent`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`triggerKeyEvent('${target}', ...)\`.`);
}
if (!eventType) {
throw new Error(`Must provide an \`eventType\` to \`triggerKeyEvent\``);
}
if (!isKeyboardEventType(eventType)) {
export default function blur(target: Target = document.activeElement!): Promise {
log('blur', target);
return nextTickPromise().then(() => {
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`blur('${target}')\`.`);
}
if (!isFocusable(element)) {
throw new Error(`${target} is not focusable`);
}
__blur__(element);
return settled();
});
}
export default function tap(target: Target, options: object = {}): Promise {
log('tap', target);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `tap`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`tap('${target}')\`.`);
}
let touchstartEv = fireEvent(element, 'touchstart', options);
let touchendEv = fireEvent(element, 'touchend', options);
if (!touchstartEv.defaultPrevented && !touchendEv.defaultPrevented) {
__click__(element, options);
export default function focus(target: Target): Promise {
log('focus', target);
return nextTickPromise().then(() => {
if (!target) {
throw new Error('Must pass an element or selector to `focus`.');
}
let element = getElement(target);
if (!element) {
throw new Error(`Element not found when calling \`focus('${target}')\`.`);
}
if (!isFocusable(element)) {
throw new Error(`${target} is not focusable`);
}
__focus__(element);