Skip to content

Commit

Permalink
added deck tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RbAvci committed Mar 3, 2024
1 parent c54bad3 commit 2c30d2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./Card.scss";

const Card = ({ title, url, image }) => {
return (
<div className="card">
<div className="card" data-testid="card">
<img src={image} alt={title} />
<div className="card-body">
<h2>{title}</h2>
Expand Down
14 changes: 12 additions & 2 deletions src/components/Deck/Deck.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Deck from "./Deck.jsx";
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import cardsData from "@/data/fakeCards.json";

describe("Deck", () => {
it("should have a test, please write one", () => {
return true;
it("renders correct card contents", () => {
render(<Deck />);

const cards = screen.getAllByTestId("card");

cardsData.forEach((cardData, index) => {
const cardElement = cards[index];
expect(cardElement).toHaveTextContent(cardData.title);
expect(cardElement.querySelector("a")).toHaveAttribute("href", cardData.url);
expect(cardElement.querySelector("img")).toHaveAttribute("src", cardData.image);
});
});
});

0 comments on commit 2c30d2c

Please sign in to comment.