Hello tries to perform a test of a function, but receives this related error.
TypeError: Cannot read properties of undefined (reading 'setFocus')
81 | this.lastFocusableElement = this.focusableElements[this.focusableElements.length - 1];
82 |
> 83 | this.firstFocusableElement.setFocus();
| ^
84 | }
85 |
86 | private clearFocusableElements(): void {
at HTMLElement.setFocus (packages/modal/src/modal.ts:83:40)
at HTMLElement.open (packages/modal/src/modal.ts:63:10)
at Object.<anonymous> (packages/modal/src/modal.test.ts:102:14)
My Function
private setFocus(): void {
this.clearFocusableElements();
this.findFocusableElements(this.querySelectorAll('*'));
this.firstFocusableElement =
this.modalElement.querySelector('.modal-close');
this.lastFocusableElement = this.focusableElements[this.focusableElements.length - 1];
this.firstFocusableElement.setFocus();
}