40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import { describe, it, expect } from "vitest";
|
|
import Stat from "../../../app/components/cards/Stat";
|
|
|
|
describe("Stat", () => {
|
|
it("renders value and label", () => {
|
|
render(
|
|
<Stat
|
|
value="420M+"
|
|
label="open source projects"
|
|
asOf="as of June 30, 2024"
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("420M+")).toBeInTheDocument();
|
|
expect(screen.getByText("open source projects")).toBeInTheDocument();
|
|
expect(screen.getByText("as of June 30, 2024")).toBeInTheDocument();
|
|
});
|
|
|
|
it("links the as-of year when a source is provided", () => {
|
|
render(
|
|
<Stat
|
|
value="420M+"
|
|
label="open source projects"
|
|
asOfPrefix="as of"
|
|
asOf="2025"
|
|
sourceHref="https://github.blog/news-insights/octoverse/octoverse-a-new-developer-joins-github-every-second-as-ai-leads-typescript-to-1/"
|
|
sourceName="GitHub Octoverse"
|
|
/>,
|
|
);
|
|
|
|
expect(
|
|
screen.getByRole("link", { name: /2025/ }),
|
|
).toHaveAttribute(
|
|
"href",
|
|
"https://github.blog/news-insights/octoverse/octoverse-a-new-developer-joins-github-every-second-as-ai-leads-typescript-to-1/",
|
|
);
|
|
});
|
|
});
|