forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.ref.test.tsx
More file actions
22 lines (19 loc) · 795 Bytes
/
Copy pathInput.ref.test.tsx
File metadata and controls
22 lines (19 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// src/components/ui/__tests__/Input.ref.test.tsx
import { render } from "@testing-library/react"
import { createRef } from "react"
import { describe, expect, it } from "vitest"
import { Input } from "@/components/ui/Input"
describe("Input ref forwarding (React 19 native ref prop)", () => {
it("populates the ref with the underlying input element", () => {
const ref = createRef<HTMLInputElement>()
render(<Input ref={ref} label="Email" />)
expect(ref.current).not.toBeNull()
expect(ref.current?.tagName).toBe("INPUT")
})
it("ref can be used to programmatically focus the input", () => {
const ref = createRef<HTMLInputElement>()
render(<Input ref={ref} label="Password" />)
ref.current?.focus()
expect(document.activeElement).toBe(ref.current)
})
})