-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathavatar.test.tsx
50 lines (45 loc) · 1.3 KB
/
avatar.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { render, screen } from "@testing-library/react";
import { createRef } from "react";
import { describe, expect, it } from "vitest";
import { Avatar, AvatarFallback } from "./avatar";
describe("Avatar", () => {
it("renders without crashing", () => {
render(<Avatar />);
const avatarElement = screen.getByTestId("avatar");
expect(avatarElement).toBeInTheDocument();
});
it("forwards ref correctly", () => {
const ref = createRef<HTMLSpanElement>();
render(<Avatar ref={ref} />);
expect(ref.current).not.toBeNull();
});
});
describe("AvatarFallback", () => {
it("renders without crashing", () => {
render(
<Avatar>
<AvatarFallback />
</Avatar>,
);
const avatarFallbackElement = screen.getByTestId("avatar-fallback");
expect(avatarFallbackElement).toBeInTheDocument();
});
it("forwards ref correctly", () => {
const ref = createRef<HTMLSpanElement>();
render(
<Avatar>
<AvatarFallback ref={ref} />
</Avatar>,
);
expect(ref.current).not.toBeNull();
});
it("displays the initials inside", () => {
render(
<Avatar>
<AvatarFallback>CC</AvatarFallback>
</Avatar>,
);
const avatarFallbackText = screen.getByText("CC");
expect(avatarFallbackText).toBeInTheDocument();
});
});