You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Allow null type for node on fireEvent and its shortcuts
A common pattern in some testing code is:
```js
const btn = document.getElementById('my-button')
fireEvent.click(btn)
```
However, `document.getElementById()` may return null and then TypeScript
will report an error:
```
error TS2345: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Document | Node | Element | Window'.
```
To resolve the TypeScript error, user can assert or check the returned
value wit something like:
```js
const btn = document.getElementById('my-button')
if (!btn) {
throw new Error("Unable to find 'my-button')
}
fireEvent.click(btn)
```
But dom-testing-library is already doing this check, so let fireEvent
accept null as a convenience to call sites.
The error already reported by dom-testing-library is:
```
Unable to fire a "click" event - please provide a DOM element.
```
0 commit comments