diff --git a/types/testing-library__dom/events.d.ts b/types/testing-library__dom/events.d.ts index 6926565717..d9c50cb790 100644 --- a/types/testing-library__dom/events.d.ts +++ b/types/testing-library__dom/events.d.ts @@ -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; diff --git a/types/testing-library__dom/testing-library__dom-tests.ts b/types/testing-library__dom/testing-library__dom-tests.ts index 830914fd7f..8615fe7b1d 100644 --- a/types/testing-library__dom/testing-library__dom-tests.ts +++ b/types/testing-library__dom/testing-library__dom-tests.ts @@ -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); }