Skip to content

Commit 79e5276

Browse files
committed
Refactor test setup to use dynamic import for cleanup function
- Updated the test setup file to use an asynchronous dynamic import for the cleanup function from @testing-library/react. - This change improves compatibility and ensures that cleanup is only called when the library is available, enhancing the robustness of the test environment.
1 parent af2387c commit 79e5276

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/test/setup.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { afterEach, beforeAll, afterAll, vi } from 'vitest';
33

44
// Cleanup after each test (only for React component tests)
55
// For pure unit tests, this is not needed
6-
try {
7-
// eslint-disable-next-line @typescript-eslint/no-var-requires
8-
const { cleanup } = require('@testing-library/react');
9-
afterEach(() => {
10-
cleanup();
11-
});
12-
} catch {
13-
// @testing-library/react not available or not needed for pure unit tests
14-
}
6+
(async () => {
7+
try {
8+
const { cleanup } = await import('@testing-library/react');
9+
afterEach(() => {
10+
cleanup();
11+
});
12+
} catch {
13+
// @testing-library/react not available or not needed for pure unit tests
14+
}
15+
})();
1516

1617
// Mock webextension-polyfill
1718
vi.mock('webextension-polyfill', () => {

0 commit comments

Comments
 (0)