Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(Selector, MultiSelector): load the lazy BottomSheet before the sheet tests (#9082)

Cindy Zhang040393bc45fc
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index a0210541be..bd0f11ed36 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -9,7 +9,15 @@
* SYNC: When MultiSelector.tsx API changes, update these tests.
*/
-import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
+import {
+ describe,
+ it,
+ expect,
+ vi,
+ beforeAll,
+ beforeEach,
+ afterEach,
+} from 'vitest';
import {
act,
render,
@@ -65,6 +73,15 @@ function politeRegion(): HTMLElement | null {
}
// Mock showPopover and hidePopover methods since they're not implemented in jsdom
+// The bottom-sheet presentation renders BottomSheet through React.lazy. Its
+// first import transforms the BottomSheet module tree, which on a loaded
+// runner takes longer than a query's 1 s wait, so the first sheet test timed
+// out before the dialog existed. Load the module once up front: lazy() then
+// resolves from the module cache and every sheet test waits only on the open.
+beforeAll(async () => {
+ await import('../BottomSheet/BottomSheet');
+});
+
beforeEach(() => {
__resetInteractionModalityForTest();
HTMLDialogElement.prototype.showModal = vi.fn(function (
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index 7878ec14ad..779d335653 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -9,7 +9,15 @@
* SYNC: When Selector.tsx API changes, update these tests.
*/
-import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
+import {
+ describe,
+ it,
+ expect,
+ vi,
+ beforeAll,
+ beforeEach,
+ afterEach,
+} from 'vitest';
import {readFileSync} from 'node:fs';
import {
act,
@@ -61,6 +69,15 @@ function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {
}
// Mock showPopover and hidePopover methods since they're not implemented in jsdom
+// The bottom-sheet presentation renders BottomSheet through React.lazy. Its
+// first import transforms the BottomSheet module tree, which on a loaded
+// runner takes longer than a query's 1 s wait, so the first sheet test timed
+// out before the dialog existed. Load the module once up front: lazy() then
+// resolves from the module cache and every sheet test waits only on the open.
+beforeAll(async () => {
+ await import('../BottomSheet/BottomSheet');
+});
+
beforeEach(() => {
// The live regions are a document-level singleton; start each test clean.
__resetLiveRegionsForTest();