-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.test.ts
More file actions
43 lines (33 loc) · 1.24 KB
/
Copy pathanalytics.test.ts
File metadata and controls
43 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { afterEach, describe, expect, it, vi } from "vitest";
const init = vi.fn();
const track = vi.fn();
vi.mock("@plausible-analytics/tracker", () => ({
init,
track,
}));
afterEach(() => {
vi.clearAllMocks();
Reflect.deleteProperty(globalThis, "window");
});
describe("analytics modules", () => {
it("can load during server rendering without browser globals", async () => {
await expect(import("../analytics")).resolves.toBeDefined();
await expect(import("../../components/PlausibleProvider")).resolves.toBeDefined();
});
it("initializes Plausible once across repeated callers", async () => {
globalThis.window = {} as Window & typeof globalThis;
const { initializePlausible } = await import("../plausible");
const config = { domain: "example.com" };
const first = initializePlausible(config);
const second = initializePlausible(config);
expect(first).toBe(second);
await first;
expect(init).toHaveBeenCalledOnce();
});
it("does not track custom events before initialization", async () => {
globalThis.window = {} as Window & typeof globalThis;
const { trackPlausible } = await import("../plausible");
await trackPlausible("signup", {});
expect(track).not.toHaveBeenCalled();
});
});