Download frontend/src/lib/confetti.test.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/confetti.test.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/lib/confetti.test.ts
-
curl -L -o confetti.test.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/confetti.test.ts
1.26 kB
| import { afterEach, describe, expect, it, vi } from "vitest"; | |
| import { celebrate } from "./confetti"; | |
| afterEach(() => { vi.restoreAllMocks(); document.body.innerHTML = ""; }); | |
| describe("celebrate", () => { | |
| it("draws over the page without catching clicks, then cleans up", () => { | |
| vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({ scale() {}, clearRect() {}, save() {}, restore() {}, translate() {}, rotate() {}, fillRect() {}, beginPath() {}, arc() {}, fill() {} } as never); | |
| const frames: FrameRequestCallback[] = []; | |
| vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => { frames.push(callback); return frames.length; }); | |
| celebrate({ x: 10, y: 10 }); | |
| const canvas = document.querySelector("canvas")!; | |
| expect(canvas.style.pointerEvents).toBe("none"); | |
| expect(canvas).toHaveAttribute("aria-hidden", "true"); | |
| frames.shift()!(performance.now() + 10_000); | |
| expect(document.querySelector("canvas")).toBeNull(); | |
| vi.unstubAllGlobals(); | |
| }); | |
| it("does nothing for people who asked for less motion", () => { | |
| vi.stubGlobal("matchMedia", () => ({ matches: true })); | |
| celebrate(); | |
| expect(document.querySelector("canvas")).toBeNull(); | |
| vi.unstubAllGlobals(); | |
| }); | |
| }); | |