/** @jsxImportSource solid-js */ import type { JSX } from "solid-js"; import { render } from "solid-js/web"; import { afterEach, describe, expect, it } from "vitest"; import { AnimatePresence, motion, Presence } from "../index.ts"; import { resolveInitialStyles } from "./_motion-state-options.ts"; describe("motion", () => { afterEach(() => { document.body.innerHTML = ""; }); it("returns a stable Solid member component for motion.div", () => { expect(motion.div).toBe(motion.div); expect(motion.button).toBe(motion.button); expect(motion.div).not.toBe(motion.button); }); it("exports Presence as a Solid-native alias for AnimatePresence", () => { expect(Presence).toBe(AnimatePresence); }); it("caches motion.create by component and forwarding mode", () => { function Card(props: JSX.HTMLAttributes) { return
; } expect(motion.create(Card)).toBe(motion.create(Card)); expect(motion.create(Card, { forwardMotionProps: true })).toBe( motion.create(Card, { forwardMotionProps: true }), ); expect(motion.create(Card)).not.toBe( motion.create(Card, { forwardMotionProps: true }), ); }); it("filters motion props from custom components unless forwarding is enabled", () => { const receivedProps: Array> = []; function Card(props: JSX.HTMLAttributes & { animate?: unknown }) { receivedProps.push(props as Record); return
; } const MotionCard = motion.create(Card); const ForwardedMotionCard = motion.create(Card, { forwardMotionProps: true }); const host = document.createElement("div"); document.body.append(host); const dispose = render(() => ( <> ), host); expect(receivedProps[0]?.animate).toBeUndefined(); expect(receivedProps[1]?.animate).toMatchObject({ opacity: 1 }); dispose(); }); it("resolves the initial target for pre-mount styles", () => { expect(resolveInitialStyles({ style: { opacity: 0.25 }, initial: { opacity: 0 }, animate: { opacity: 1 }, })).toMatchObject({ opacity: 0 }); }); });