Files
formbricks/packages/lib/vitestSetup.ts
2024-02-26 22:31:52 +01:00

34 lines
759 B
TypeScript

// mock these globally used functions
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { ValidationError } from "@formbricks/types/errors";
vi.mock("next/cache", () => ({
__esModule: true,
unstable_cache: (fn: () => {}) => {
return async () => {
return fn();
};
},
revalidateTag: vi.fn(),
}));
vi.mock("server-only", () => {
return {};
});
beforeEach(() => {
vi.resetModules();
vi.resetAllMocks();
});
afterEach(() => {
vi.clearAllMocks();
});
export const testInputValidation = async (service: Function, ...args: any[]): Promise<void> => {
it("it should throw a ValidationError if the inputs are invalid", async () => {
await expect(service(...args)).rejects.toThrow(ValidationError);
});
};