-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestimonialcard.test.js
35 lines (30 loc) · 1.12 KB
/
testimonialcard.test.js
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
import React from "react";
import { render, screen } from "@testing-library/react";
import TestimonialCard from "./TestimonialCard";
describe("TestimonialCard component", () => {
const sampleData = {
author: "John Doe",
description: "This is a sample testimonial.",
image: "profile-picture.jpg",
rating: 4,
};
test("renders the TestimonialCard component with given data", () => {
render(
<TestimonialCard
author={sampleData.author}
description={sampleData.description}
image={sampleData.image}
rating={sampleData.rating}
/>
);
// Check if the author name is rendered
const authorElement = screen.getByText(sampleData.author);
expect(authorElement).toBeInTheDocument();
// Check if the description is rendered
const descriptionElement = screen.getByText(sampleData.description);
expect(descriptionElement).toBeInTheDocument();
// Check if the star icons are rendered based on the rating
const starIcons = screen.getAllByAltText("star");
expect(starIcons.length).toBe(sampleData.rating);
});
});