Add ChildNode to union in fireEvent element arg (#42215)

* Add ChildNode to union in fireEvent element arg

* Add ChildNode test to eventTest()

* Changing ChildNode to its super type Node for typescript@3.0 compatibility
This commit is contained in:
Philip Bulley
2020-02-10 09:49:57 -08:00
committed by GitHub
parent 72ce5b2ea5
commit 92a4daec29
2 changed files with 15 additions and 3 deletions
+3 -3
View File
@@ -83,12 +83,12 @@ export type EventType =
| 'gotPointerCapture'
| 'lostPointerCapture';
export type FireFunction = (element: Document | Element | Window, event: Event) => boolean;
export type FireFunction = (element: Document | Element | Window | Node, event: Event) => boolean;
export type FireObject = {
[K in EventType]: (element: Document | Element | Window, options?: {}) => boolean;
[K in EventType]: (element: Document | Element | Window | Node, options?: {}) => boolean;
};
export type CreateObject = {
[K in EventType]: (element: Document | Element | Window, options?: {}) => Event;
[K in EventType]: (element: Document | Element | Window | Node, options?: {}) => Event;
};
export const createEvent: CreateObject;
@@ -51,4 +51,16 @@ function eventTest() {
location: 'http://www.example.com/?page=1',
state: { page: 1 },
});
// HTMLElement
const element = document.createElement('div');
fireEvent.click(getByText(element, 'foo'));
// ChildNode
const child = document.createElement('div');
element.appendChild(child);
if (!element.firstChild) { // Narrow Type
throw new Error(`Can't find firstChild`);
}
fireEvent.click(element.firstChild);
}