Skip to content

Commit e85ffef

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent b70be81 commit e85ffef

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/initializers/app-entry-point-extension-initializer.test.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,34 @@ class UmbTestAppEntryPointHostElement extends UmbElementMixin(HTMLElement) {}
1111

1212
const ALIAS = 'Umb.Test.AppEntryPoint';
1313

14-
const waitLoaded = (initializer: UmbAppEntryPointExtensionInitializer) =>
15-
new Promise<void>((resolve) => {
16-
const sub = initializer.loaded.subscribe((value) => {
17-
if (value === true) {
18-
resolve();
19-
queueMicrotask(() => sub.unsubscribe());
20-
}
21-
});
22-
});
14+
const waitLoaded = async (
15+
initializer: UmbAppEntryPointExtensionInitializer,
16+
timeout = 100,
17+
) => {
18+
let sub: { unsubscribe: () => void } | undefined;
19+
const cleanup = () => sub?.unsubscribe();
20+
21+
try {
22+
await Promise.race([
23+
new Promise<void>((resolve) => {
24+
sub = initializer.loaded.subscribe((value) => {
25+
if (value === true) {
26+
cleanup();
27+
resolve();
28+
}
29+
});
30+
}),
31+
aTimeout(timeout).then(() => {
32+
cleanup();
33+
throw new Error(
34+
`Timed out after ${timeout}ms waiting for UmbAppEntryPointExtensionInitializer.loaded to emit true.`,
35+
);
36+
}),
37+
]);
38+
} finally {
39+
cleanup();
40+
}
41+
};
2342

2443
describe('UmbAppEntryPointExtensionInitializer', () => {
2544
let host: UmbElement;

0 commit comments

Comments
 (0)