forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.ref.test.tsx
More file actions
23 lines (20 loc) · 798 Bytes
/
Copy pathButton.ref.test.tsx
File metadata and controls
23 lines (20 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// src/components/ui/__tests__/Button.ref.test.tsx
import { render } from "@testing-library/react"
import { createRef } from "react"
import { describe, expect, it } from "vitest"
import { Button } from "@/components/ui/Button"
describe("Button ref forwarding (React 19 native ref prop)", () => {
it("populates the ref with the underlying button element", () => {
const ref = createRef<HTMLButtonElement>()
render(<Button ref={ref}>Click</Button>)
expect(ref.current).not.toBeNull()
expect(ref.current?.tagName).toBe("BUTTON")
})
it("ref is null after unmount", () => {
const ref = createRef<HTMLButtonElement>()
const { unmount } = render(<Button ref={ref}>X</Button>)
expect(ref.current).not.toBeNull()
unmount()
expect(ref.current).toBeNull()
})
})