You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/11/05 01:05:11 UTC
(superset) 03/07: fix(DatasourceControl): enhance afterEach cleanup to prevent test pollution
This is an automated email from the ASF dual-hosted git repository.
jli pushed a commit to branch api-mocks-for-datasource-control
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b01176d8fb9e74a252bb64db443fdcd6c4bfe646
Author: Joe Li <jo...@preset.io>
AuthorDate: Fri Oct 24 14:36:33 2025 -0700
fix(DatasourceControl): enhance afterEach cleanup to prevent test pollution
Improved test cleanup to follow best practices from PR #35334 and eliminate
potential test pollution issues. The enhanced cleanup ensures that all React
components are properly unmounted, mocks are reset, and test state is cleared
between test runs.
Changes:
- Added cleanup() to explicitly unmount React components and clear RTL state
- Added jest.restoreAllMocks() to restore original implementations of all mocks
(including the module-level SupersetClientGet spy) and clear call history
- This is more thorough than clearAllMocks() which only clears history
Benefits:
- Prevents test pollution between tests
- Ensures module-level spy is properly cleaned after each test
- Follows Superset test modernization best practices
- All 21 tests continue to pass cleanly
This is part of Issue #3 in the test flakiness investigation for
DatasourceControl.test.tsx.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <no...@anthropic.com>
---
.../components/controls/DatasourceControl/DatasourceControl.test.tsx | 3 +++
1 file changed, 3 insertions(+)
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
index 47a78ad1a9..8377c79b03 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
@@ -26,6 +26,7 @@ import {
act,
userEvent,
waitFor,
+ cleanup,
} from 'spec/helpers/testing-library';
import { fallbackExploreInitialData } from 'src/explore/fixtures';
import DatasourceControl from '.';
@@ -33,8 +34,10 @@ import DatasourceControl from '.';
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
afterEach(() => {
+ cleanup();
fetchMock.reset();
fetchMock.restore();
+ jest.restoreAllMocks();
});
const mockDatasource = {