Files
agentic-dev/packages/core-analytics/src/noop-analytics.test.ts
Danijel Martinek 563eab06a6 feat(core-analytics): add IAnalytics interface, types, and NoopAnalytics
Replaces generator placeholder with IAnalytics interface (track, identify,
pageView, flush), AnalyticsAttributeValue + AnalyticsUser types, and
NoopAnalytics implementation. Adds sibling tests covering all four methods
with 100% coverage. All conformance + coverage gates pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 11:31:58 +00:00

55 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { NoopAnalytics } from "@/noop-analytics";
describe("NoopAnalytics", () => {
it("track() does not throw with event name only", () => {
const analytics = new NoopAnalytics();
expect(() => analytics.track("page_viewed")).not.toThrow();
});
it("track() does not throw with event name and attributes", () => {
const analytics = new NoopAnalytics();
expect(() =>
analytics.track("button_clicked", {
label: "signup",
count: 1,
active: true,
}),
).not.toThrow();
});
it("identify() does not throw with user only", () => {
const analytics = new NoopAnalytics();
expect(() => analytics.identify({ id: "user-123" })).not.toThrow();
});
it("identify() does not throw with user and attributes", () => {
const analytics = new NoopAnalytics();
expect(() =>
analytics.identify({ id: "user-123" }, { plan: "pro", trial: false }),
).not.toThrow();
});
it("pageView() does not throw with path only", () => {
const analytics = new NoopAnalytics();
expect(() => analytics.pageView("/dashboard")).not.toThrow();
});
it("pageView() does not throw with path and attributes", () => {
const analytics = new NoopAnalytics();
expect(() =>
analytics.pageView("/dashboard", { referrer: "/home", duration: 120 }),
).not.toThrow();
});
it("flush() resolves without throwing", async () => {
const analytics = new NoopAnalytics();
await expect(analytics.flush()).resolves.toBeUndefined();
});
it("flush() returns a Promise", () => {
const analytics = new NoopAnalytics();
expect(analytics.flush()).toBeInstanceOf(Promise);
});
});