diff --git a/apps/v4/registry/bases/radix/ui/button.test.tsx b/apps/v4/registry/bases/radix/ui/button.test.tsx new file mode 100644 index 00000000000..baae520dd9d --- /dev/null +++ b/apps/v4/registry/bases/radix/ui/button.test.tsx @@ -0,0 +1,22 @@ +import * as React from "react" +import { renderToStaticMarkup } from "react-dom/server" +import { describe, expect, it } from "vitest" + +import { Button } from "./button" + +describe("radix button", () => { + it("is a forwardRef component", () => { + expect(Button.$$typeof).toBe(Symbol.for("react.forward_ref")) + }) + + it("renders an asChild child without wrapping", () => { + const html = renderToStaticMarkup( + + ) + + expect(html).toMatch(/^]*>Action<\/span>$/) + expect(html).not.toContain(" & +type ButtonProps = React.ComponentProps<"button"> & VariantProps & { asChild?: boolean - }) { + } + +const Button = React.forwardRef(function Button( + { + className, + variant = "default", + size = "default", + asChild = false, + ...props + }, + ref +) { const Comp = asChild ? Slot.Root : "button" return ( ) -} +}) + +Button.displayName = "Button" export { Button, buttonVariants } diff --git a/apps/v4/registry/new-york-v4/ui/button.test.tsx b/apps/v4/registry/new-york-v4/ui/button.test.tsx new file mode 100644 index 00000000000..17d538b7f6d --- /dev/null +++ b/apps/v4/registry/new-york-v4/ui/button.test.tsx @@ -0,0 +1,22 @@ +import * as React from "react" +import { renderToStaticMarkup } from "react-dom/server" +import { describe, expect, it } from "vitest" + +import { Button } from "./button" + +describe("new-york Button", () => { + it("is a forwardRef component", () => { + expect(Button.$$typeof).toBe(Symbol.for("react.forward_ref")) + }) + + it("renders an asChild child without wrapping", () => { + const html = renderToStaticMarkup( + + ) + + expect(html).toMatch(/^]*>Action<\/span>$/) + expect(html).not.toContain(" & +type ButtonProps = React.ComponentProps<"button"> & VariantProps & { asChild?: boolean - }) { + } + +const Button = React.forwardRef(function Button( + { + className, + variant = "default", + size = "default", + asChild = false, + ...props + }, + ref +) { const Comp = asChild ? Slot.Root : "button" return ( ) -} +}) + +Button.displayName = "Button" export { Button, buttonVariants }