Files
OpenHands/__tests__/utils/error-handler.test.ts
T
Hiep Leandallhands-bot 37d5c1dfa0 chore: remove unused utility functions (#560)
* chore: remove unused utility functions

* chore: Remove PR-only artifacts

---------

Co-authored-by: allhands-bot <allhands-bot@users.noreply.github.com>
2026-05-18 10:57:40 +07:00

62 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import posthog from "posthog-js";
import { trackError } from "#/utils/error-handler";
vi.mock("posthog-js", () => ({
default: {
captureException: vi.fn(),
},
}));
describe("Error Handler", () => {
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
vi.clearAllMocks();
});
describe("trackError", () => {
it("should send error to PostHog with basic info", () => {
const error = {
message: "Test error",
source: "test",
posthog,
};
trackError(error);
expect(posthog.captureException).toHaveBeenCalledWith(
new Error("Test error"),
{
error_source: "test",
},
);
});
it("should include additional metadata in PostHog event", () => {
const error = {
message: "Test error",
source: "test",
metadata: {
extra: "info",
details: { foo: "bar" },
},
posthog,
};
trackError(error);
expect(posthog.captureException).toHaveBeenCalledWith(
new Error("Test error"),
{
error_source: "test",
extra: "info",
details: { foo: "bar" },
},
);
});
});
});