Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/solid-motion-experiments.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172/** @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<HTMLElement>) { return <article {...props} />; }
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<Record<string, unknown>> = [];
function Card(props: JSX.HTMLAttributes<HTMLElement> & { animate?: unknown }) { receivedProps.push(props as Record<string, unknown>); return <article data-testid="card" {...props} />; }
const MotionCard = motion.create(Card); const ForwardedMotionCard = motion.create(Card, { forwardMotionProps: true }); const host = document.createElement("div"); document.body.append(host);
const dispose = render(() => ( <> <MotionCard data-testid="filtered" animate={{ opacity: 1 }} /> <ForwardedMotionCard data-testid="forwarded" animate={{ opacity: 1 }} /> </> ), 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 }); });});