fix(webhelpers): improve browser test fixture to append element and await custom element upgrade and Lit update completion; add generic return type; update npm packaging release config; remove pnpm onlyBuiltDependencies
This commit is contained in:
@@ -22,10 +22,24 @@ class WebHelpers {
|
||||
|
||||
// Initialize fixture function based on environment
|
||||
if (smartenv.isBrowser) {
|
||||
this.fixture = async (htmlString: string): Promise<HTMLElement> => {
|
||||
this.fixture = async <T extends HTMLElement>(htmlString: string): Promise<T> => {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = htmlString.trim();
|
||||
const element = container.firstChild as HTMLElement;
|
||||
const element = container.firstElementChild as T;
|
||||
|
||||
// Append to document so custom elements upgrade and lifecycle hooks fire
|
||||
document.body.appendChild(element);
|
||||
|
||||
// Wait for custom element definition if it's a custom element
|
||||
if (element.localName.includes('-')) {
|
||||
await customElements.whenDefined(element.localName).catch(() => {});
|
||||
}
|
||||
|
||||
// Wait for Lit/async components to finish rendering
|
||||
if ((element as any).updateComplete) {
|
||||
await (element as any).updateComplete;
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user