Files
workavia-calendar-front/__test__/features/Error/ErrorHandler.test.tsx
T
2025-10-10 11:19:09 +02:00

36 lines
1.0 KiB
TypeScript

import { EventErrorHandler } from "../../../src/components/Error/EventErrorHandler";
describe("EventErrorHandler", () => {
it("calls the callback when a new error is reported", () => {
const handler = new EventErrorHandler();
const callback = jest.fn();
handler.setErrorCallback(callback);
handler.reportError("123", "Something broke");
expect(callback).toHaveBeenCalledWith(["Something broke"]);
});
it("does not duplicate errors for same eventId", () => {
const handler = new EventErrorHandler();
const callback = jest.fn();
handler.setErrorCallback(callback);
handler.reportError("A", "Error 1");
handler.reportError("A", "Error 1 again");
expect(callback).toHaveBeenCalledTimes(1);
});
it("clears errors properly", () => {
const handler = new EventErrorHandler();
const callback = jest.fn();
handler.setErrorCallback(callback);
handler.reportError("A", "Error 1");
handler.clearAll();
expect(callback).toHaveBeenLastCalledWith([]);
});
});