-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleaner dispatching of fake events
- Loading branch information
Showing
2 changed files
with
13 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import { | ||
createFakeEvent, | ||
createKeyboardEvent, | ||
createMouseEvent | ||
} from './event-objects'; | ||
import {createFakeEvent, createKeyboardEvent, createMouseEvent} from './event-objects'; | ||
|
||
/** Shorthand to dispatch a fake event on a specified node. */ | ||
export function dispatchFakeEvent(node: Node | Window, type: string) { | ||
let event = createFakeEvent(type); | ||
/** Utility to dispatch any event on a Node. */ | ||
export function dispatchEvent(node: Node | Window, event: Event): Event { | ||
node.dispatchEvent(event); | ||
return event; | ||
} | ||
|
||
/** Shorthand to dispatch a fake event on a specified node. */ | ||
export function dispatchFakeEvent(node: Node | Window, type: string): Event { | ||
return dispatchEvent(node, createFakeEvent(type)); | ||
} | ||
|
||
/** Shorthand to dispatch a keyboard event with a specified key code. */ | ||
export function dispatchKeyboardEvent(node: Node, type: string, keyCode: number) { | ||
let event = createKeyboardEvent(type, keyCode); | ||
node.dispatchEvent(event); | ||
return event; | ||
export function dispatchKeyboardEvent(node: Node, type: string, keyCode: number): KeyboardEvent { | ||
return dispatchEvent(node, createKeyboardEvent(type, keyCode)) as KeyboardEvent; | ||
} | ||
|
||
/** Shorthand to dispatch a mouse event on the specified coordinates. */ | ||
export function dispatchMouseEvent(node: Node, type: string, x = 0, y = 0) { | ||
let event = createMouseEvent(type, x, y); | ||
node.dispatchEvent(event); | ||
return event; | ||
export function dispatchMouseEvent(node: Node, type: string, x = 0, y = 0): MouseEvent { | ||
return dispatchEvent(node, createMouseEvent(type, x, y)) as MouseEvent; | ||
} |
This file contains 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