import { describe, it, expectTypeOf } from "vitest"; import type { Observable } from "@legendapp/state"; import type { ReadonlyObservable } from "@usels/core"; import { useAnimate, type UseAnimateReturn, type UseAnimateKeyframes, type UseAnimateOptions, } from "."; // --------------------------------------------------------------------------- // useAnimate() — Type-Level Tests // --------------------------------------------------------------------------- describe("useAnimate() \u2014 types", () => { describe("return type", () => { it("UseAnimateReturn includes all control methods", () => { expectTypeOf().toBeFunction(); expectTypeOf().toBeFunction(); expectTypeOf().toBeFunction(); expectTypeOf().toBeFunction(); expectTypeOf().toBeFunction(); }); it("isSupported$ is ReadonlyObservable", () => { expectTypeOf().toEqualTypeOf>(); }); it("animate$ is ReadonlyObservable", () => { expectTypeOf().toEqualTypeOf< ReadonlyObservable >(); }); it("playState$ is ReadonlyObservable", () => { expectTypeOf().toEqualTypeOf< ReadonlyObservable >(); }); it("currentTime$ is Observable", () => { expectTypeOf().toEqualTypeOf>(); }); it("playbackRate$ is Observable", () => { expectTypeOf().toEqualTypeOf>(); }); }); describe("option types", () => { it("second parameter type is UseAnimateKeyframes", () => { expectTypeOf().parameter(1).toEqualTypeOf(); }); it("UseAnimateOptions has immediate field of type boolean | undefined", () => { expectTypeOf().toEqualTypeOf(); }); it("UseAnimateOptions has commitStyles field of type boolean | undefined", () => { expectTypeOf().toEqualTypeOf(); }); it("UseAnimateOptions has playbackRate field of type number | undefined", () => { expectTypeOf().toEqualTypeOf(); }); it("UseAnimateOptions has onReady callback field", () => { expectTypeOf().toEqualTypeOf< ((animate: Animation) => void) | undefined >(); }); it("UseAnimateOptions has onError callback field", () => { expectTypeOf().toEqualTypeOf< ((e: unknown) => void) | undefined >(); }); it("UseAnimateKeyframes second parameter accepts Observable", () => { // Observable is a subtype of UseAnimateKeyframes (MaybeObservable union) // Verify by checking the parameter type includes Observable type Param1 = Parameters[1]; expectTypeOf().toEqualTypeOf(); }); }); });