mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 02:10:12 -06:00
- Create centralized TEST_IDS constants to eliminate 200+ magic string occurrences - Create FIXTURES for common test data to reduce 47+ duplicate definitions - Add setupTestEnvironment() helper to standardize cleanup patterns (36+ occurrences) - Export utilities from vitestSetup.ts for easy access - Add comprehensive README with usage examples This is Phase 1 (Quick Wins) of the testing infrastructure refactor. Estimated impact: 30-50% reduction in test boilerplate for new tests. Related analysis documents: TESTING_ANALYSIS_README.md, ANALYSIS_SUMMARY.txt
32 lines
732 B
TypeScript
32 lines
732 B
TypeScript
import { afterEach, beforeEach, vi } from "vitest";
|
|
|
|
/**
|
|
* Standard test environment setup with consistent cleanup patterns.
|
|
* Call this function once at the top of your test file to ensure
|
|
* mocks are properly cleaned up between tests.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* import { setupTestEnvironment } from "@/lib/testing/setup";
|
|
*
|
|
* setupTestEnvironment();
|
|
*
|
|
* describe("MyModule", () => {
|
|
* test("should work correctly", () => {
|
|
* // Your test code here
|
|
* });
|
|
* });
|
|
* ```
|
|
*
|
|
* Note: This replaces manual beforeEach/afterEach blocks in individual test files.
|
|
*/
|
|
export function setupTestEnvironment() {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
}
|