Spaces:
Configuration error
Configuration error
Download frontend/__tests__/utils/handle-capture-consent.test.ts from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/__tests__/utils/handle-capture-consent.test.ts
- Command line
-
hf download hf://spaces/flyingdarkdev/README/frontend/__tests__/utils/handle-capture-consent.test.ts
-
curl -L -o handle-capture-consent.test.ts https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/__tests__/utils/handle-capture-consent.test.ts
1.4 kB
| import posthog from "posthog-js"; | |
| import { afterEach, describe, expect, it, vi } from "vitest"; | |
| import { handleCaptureConsent } from "#/utils/handle-capture-consent"; | |
| describe("handleCaptureConsent", () => { | |
| const optInSpy = vi.spyOn(posthog, "opt_in_capturing"); | |
| const optOutSpy = vi.spyOn(posthog, "opt_out_capturing"); | |
| const hasOptedInSpy = vi.spyOn(posthog, "has_opted_in_capturing"); | |
| const hasOptedOutSpy = vi.spyOn(posthog, "has_opted_out_capturing"); | |
| afterEach(() => { | |
| vi.clearAllMocks(); | |
| }); | |
| it("should opt out of of capturing", () => { | |
| handleCaptureConsent(false); | |
| expect(optOutSpy).toHaveBeenCalled(); | |
| expect(optInSpy).not.toHaveBeenCalled(); | |
| }); | |
| it("should opt in to capturing if the user consents", () => { | |
| handleCaptureConsent(true); | |
| expect(optInSpy).toHaveBeenCalled(); | |
| expect(optOutSpy).not.toHaveBeenCalled(); | |
| }); | |
| it("should not opt in to capturing if the user is already opted in", () => { | |
| hasOptedInSpy.mockReturnValueOnce(true); | |
| handleCaptureConsent(true); | |
| expect(optInSpy).not.toHaveBeenCalled(); | |
| expect(optOutSpy).not.toHaveBeenCalled(); | |
| }); | |
| it("should not opt out of capturing if the user is already opted out", () => { | |
| hasOptedOutSpy.mockReturnValueOnce(true); | |
| handleCaptureConsent(false); | |
| expect(optOutSpy).not.toHaveBeenCalled(); | |
| expect(optInSpy).not.toHaveBeenCalled(); | |
| }); | |
| }); | |