Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/solid-motion-experiments.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import { describe, expect, it } from "vitest";
import type { SolidMotionAdapter } from "../adapter/types.ts";import { MOTION_PROP_KEYS, splitMotionProps } from "./split-motion-props.ts";
const fakeAdapter = { splitProps(props: Record<PropertyKey, unknown>, keys: readonly PropertyKey[]) { const motionProps = Object.create(null) as Record<PropertyKey, unknown>; const domProps = Object.create(null) as Record<PropertyKey, unknown>; const keySet = new Set<PropertyKey>(keys);
for (const key of Reflect.ownKeys(props)) { const target = keySet.has(key) ? motionProps : domProps;
Object.defineProperty(target, key, { enumerable: true, get: () => props[key], }); }
return [motionProps, domProps] as never; },} as unknown as Pick<SolidMotionAdapter, "splitProps">;
describe("splitMotionProps", () => { it("keeps Motion-owned props out of the DOM prop bag", () => { const [motionProps, domProps] = splitMotionProps( { id: "card", class: "rounded", animate: { opacity: 1 }, initial: { opacity: 0 }, style: { opacity: 0.5 }, whileHover: { scale: 1.05 }, drag: "x", presenceKey: "card-a", onClick: () => undefined, }, fakeAdapter, );
expect(Object.keys(motionProps).sort()).toEqual([ "animate", "drag", "initial", "presenceKey", "style", "whileHover", ]); expect(Object.keys(domProps).sort()).toEqual(["class", "id", "onClick"]); });
it("does not invoke accessor-valued motion props while splitting", () => { let reads = 0; const rawProps = { get animate() { reads += 1; return { opacity: 1 }; }, id: "box", };
const [motionProps] = splitMotionProps(rawProps, fakeAdapter);
expect(reads).toBe(0); expect(motionProps.animate).toEqual({ opacity: 1 }); expect(reads).toBe(1); });
it("tracks the Milestone 0 and near-MVP Motion prop surface", () => { expect(MOTION_PROP_KEYS).toEqual(expect.arrayContaining([ "initial", "animate", "exit", "transition", "variants", "style", "presenceKey", "layout", "layoutDependency", "whileHover", "whileTap", "whileFocus", "whileDrag", "whileInView", "drag", ])); });});