Files
portfolio/app/__tests__/components/CurrentlyReading.test.tsx
denshooter 32abc7f3ef
All checks were successful
CI / CD / test-build (push) Successful in 10m13s
CI / CD / deploy-dev (push) Successful in 1m48s
CI / CD / deploy-production (push) Has been skipped
fix: update tests for dk0 logo and boneyard-js mock, add jest moduleNameMapper
2026-04-15 14:37:50 +02:00

50 lines
1.4 KiB
TypeScript

import { render, screen, waitFor } from "@testing-library/react";
import CurrentlyReadingComp from "@/app/components/CurrentlyReading";
import React from "react";
jest.mock("next-intl", () => ({
useTranslations: () => (key: string) => key,
useLocale: () => "en",
}));
jest.mock("next/image", () => ({
__esModule: true,
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => <img {...props} alt={props.alt || ""} />,
}));
describe("CurrentlyReading Component", () => {
beforeEach(() => {
global.fetch = jest.fn();
});
it("renders skeleton when loading", () => {
(global.fetch as jest.Mock).mockReturnValue(new Promise(() => {}));
render(<CurrentlyReadingComp />);
expect(screen.getByTestId("boneyard-skeleton")).toBeInTheDocument();
});
it("renders a book when data is fetched", async () => {
const mockBooks = [
{
title: "Test Book",
authors: ["Test Author"],
image: "/test.jpg",
progress: 50,
startedAt: "2024-01-01"
},
];
(global.fetch as jest.Mock).mockResolvedValue({
ok: true,
json: async () => ({ currentlyReading: mockBooks }),
});
render(<CurrentlyReadingComp />);
await waitFor(() => {
expect(screen.getByText("Test Book")).toBeInTheDocument();
expect(screen.getByText("Test Author")).toBeInTheDocument();
});
});
});