Skip to content

Commit d7aef53

Browse files
committed
fix(bridge): fix TypeScript errors in tests and command handler
- Add qs() helper for type-safe element queries in happy-dom tests - Make comms-url handler async to match registerCommand signature - Downgrade require-await to warning (async-without-await is required by some pi API signatures) - Add test/helpers.ts to ESLint test file overrides - Guard indexed access with assert.ok before property access
1 parent a44a52a commit d7aef53

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Shared test helpers for frontend component tests.
3+
*/
4+
5+
/**
6+
* Query selector that returns HTMLElement.
7+
* Throws if element not found. Uses type narrowing suitable for
8+
* happy-dom (where elements are not instanceof HTMLElement).
9+
*/
10+
export function qs(parent: ParentNode, selector: string): HTMLElement {
11+
const el = parent.querySelector(selector);
12+
if (el === null) {
13+
throw new Error(`HTMLElement not found: ${selector}`);
14+
}
15+
if ("click" in el && "style" in el) {
16+
return el as HTMLElement;
17+
}
18+
throw new Error(
19+
`Element ${selector} is not an HTMLElement: ${el.constructor.name}`,
20+
);
21+
}

0 commit comments

Comments
 (0)