Files
formbricks-formbricks/apps/web/lib/testing/setup.ts
Johannes b05a636914 feat: add Phase 1 testing utilities (TEST_IDS, FIXTURES, setupTestEnvironment)
- 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
2025-11-24 13:54:59 +01:00

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();
});
}