You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2026/04/10 04:47:55 UTC
(superset) 01/01: fix(tests): improve ShareMenuItems test isolation to fix intermittent suite failure
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch fix-share-menu-items-flaky
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 678c1b27572738b6d8e4ed492be0e865edae60d0
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Fri Apr 10 04:47:36 2026 +0000
fix(tests): improve ShareMenuItems test isolation to fix intermittent suite failure
- Move window.location setup/teardown from beforeAll/afterAll to beforeEach/afterEach
for proper per-test isolation
- Clean up window.featureFlags in afterEach (was leaking across tests and suites)
- Reset fetchMock routes and history in beforeEach/afterEach instead of only setting
up once in beforeAll (stale route state could corrupt worker)
- Add await to userEvent.click() calls to prevent fire-and-forget race conditions
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../menu/ShareMenuItems/ShareMenuItems.test.tsx | 36 ++++++++++------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
index 3e137d2c874..f58527abc94 100644
--- a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
+++ b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx
@@ -45,13 +45,17 @@ const createProps = () => ({
submenuKey: 'share',
});
-const { location } = window;
+const originalLocation = window.location;
const postDashboardPermalinkMockUrl = `http://localhost/api/v1/dashboard/${DASHBOARD_ID}/permalink`;
-beforeAll((): void => {
+beforeEach(() => {
+ jest.clearAllMocks();
// @ts-expect-error
delete window.location;
+ window.location = { href: '' } as any;
+ fetchMock.removeRoutes();
+ fetchMock.clearHistory();
fetchMock.post(
postDashboardPermalinkMockUrl,
{ key: '123', url: 'http://localhost/superset/dashboard/p/123/' },
@@ -59,15 +63,11 @@ beforeAll((): void => {
);
});
-beforeEach(() => {
- jest.clearAllMocks();
- window.location = {
- href: '',
- } as any;
-});
-
-afterAll((): void => {
- window.location = location;
+afterEach(() => {
+ window.location = originalLocation;
+ delete window.featureFlags;
+ fetchMock.removeRoutes();
+ fetchMock.clearHistory();
});
const MenuWrapper = (
@@ -113,7 +113,7 @@ test('Click on "Copy dashboard URL" and succeed', async () => {
expect(props.addDangerToast).toHaveBeenCalledTimes(0);
});
- userEvent.click(screen.getByText('Copy dashboard URL'));
+ await userEvent.click(screen.getByText('Copy dashboard URL'));
await waitFor(async () => {
expect(spy).toHaveBeenCalledTimes(1);
@@ -145,7 +145,7 @@ test('Click on "Copy dashboard URL" and fail', async () => {
expect(props.addDangerToast).toHaveBeenCalledTimes(0);
});
- userEvent.click(screen.getByText('Copy dashboard URL'));
+ await userEvent.click(screen.getByText('Copy dashboard URL'));
await waitFor(async () => {
expect(spy).toHaveBeenCalledTimes(1);
@@ -177,7 +177,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
expect(window.location.href).toBe('');
});
- userEvent.click(screen.getByText('Share dashboard by email'));
+ await userEvent.click(screen.getByText('Share dashboard by email'));
await waitFor(() => {
expect(props.addDangerToast).toHaveBeenCalledTimes(0);
@@ -189,11 +189,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
test('Click on "Share dashboard by email" and fail', async () => {
fetchMock.removeRoute(postDashboardPermalinkMockUrl);
- fetchMock.post(
- `http://localhost/api/v1/dashboard/${DASHBOARD_ID}/permalink`,
- { status: 404 },
- { name: postDashboardPermalinkMockUrl },
- );
+ fetchMock.post(postDashboardPermalinkMockUrl, { status: 404 });
const props = createProps();
render(
<MenuWrapper
@@ -211,7 +207,7 @@ test('Click on "Share dashboard by email" and fail', async () => {
expect(window.location.href).toBe('');
});
- userEvent.click(screen.getByText('Share dashboard by email'));
+ await userEvent.click(screen.getByText('Share dashboard by email'));
await waitFor(() => {
expect(window.location.href).toBe('');