fix: update tests for dk0 logo and boneyard-js mock, add jest moduleNameMapper
This commit is contained in:
6
__mocks__/boneyard-js/react.tsx
Normal file
6
__mocks__/boneyard-js/react.tsx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export function Skeleton({ children, loading }: { children: React.ReactNode; loading: boolean; name?: string; animate?: string; transition?: boolean | number }) {
|
||||||
|
if (loading) return <div data-testid="boneyard-skeleton">Loading...</div>;
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
@@ -2,16 +2,13 @@ import { render, screen, waitFor } from "@testing-library/react";
|
|||||||
import CurrentlyReadingComp from "@/app/components/CurrentlyReading";
|
import CurrentlyReadingComp from "@/app/components/CurrentlyReading";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
// Mock next-intl completely to avoid ESM issues
|
|
||||||
jest.mock("next-intl", () => ({
|
jest.mock("next-intl", () => ({
|
||||||
useTranslations: () => (key: string) => key,
|
useTranslations: () => (key: string) => key,
|
||||||
useLocale: () => "en",
|
useLocale: () => "en",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock next/image
|
|
||||||
jest.mock("next/image", () => ({
|
jest.mock("next/image", () => ({
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
|
||||||
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => <img {...props} alt={props.alt || ""} />,
|
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => <img {...props} alt={props.alt || ""} />,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -22,8 +19,8 @@ describe("CurrentlyReading Component", () => {
|
|||||||
|
|
||||||
it("renders skeleton when loading", () => {
|
it("renders skeleton when loading", () => {
|
||||||
(global.fetch as jest.Mock).mockReturnValue(new Promise(() => {}));
|
(global.fetch as jest.Mock).mockReturnValue(new Promise(() => {}));
|
||||||
const { container } = render(<CurrentlyReadingComp />);
|
render(<CurrentlyReadingComp />);
|
||||||
expect(container.querySelector(".animate-pulse")).toBeInTheDocument();
|
expect(screen.getByTestId("boneyard-skeleton")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders a book when data is fetched", async () => {
|
it("renders a book when data is fetched", async () => {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ jest.mock('next/navigation', () => ({
|
|||||||
describe('Header', () => {
|
describe('Header', () => {
|
||||||
it('renders the header with the dk logo', () => {
|
it('renders the header with the dk logo', () => {
|
||||||
render(<Header />);
|
render(<Header />);
|
||||||
expect(screen.getByText('dk')).toBeInTheDocument();
|
expect(screen.getByText('dk0')).toBeInTheDocument();
|
||||||
|
|
||||||
// Check for navigation links (appear in both desktop and mobile menus)
|
// Check for navigation links (appear in both desktop and mobile menus)
|
||||||
expect(screen.getAllByText('Home').length).toBeGreaterThan(0);
|
expect(screen.getAllByText('Home').length).toBeGreaterThan(0);
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ const config: Config = {
|
|||||||
testPathIgnorePatterns: ["/node_modules/", "/__mocks__/", "/.next/", "/e2e/"],
|
testPathIgnorePatterns: ["/node_modules/", "/__mocks__/", "/.next/", "/e2e/"],
|
||||||
// Transform react-markdown and other ESM modules
|
// Transform react-markdown and other ESM modules
|
||||||
transformIgnorePatterns: [
|
transformIgnorePatterns: [
|
||||||
"node_modules/(?!(react-markdown|remark-.*|rehype-.*|unified|bail|is-plain-obj|trough|vfile|vfile-message|unist-.*|micromark|parse-entities|character-entities|mdast-.*|hast-.*|property-information|space-separated-tokens|comma-separated-tokens|web-namespaces|zwitch|longest-streak|ccount)/)",
|
"node_modules/(?!(react-markdown|remark-.*|rehype-.*|unified|bail|is-plain-obj|trough|vfile|vfile-message|unist-.*|micromark|parse-entities|character-entities|mdast-.*|hast-.*|property-information|space-separated-tokens|comma-separated-tokens|web-namespaces|zwitch|longest-streak|ccount|boneyard-js)/)",
|
||||||
],
|
],
|
||||||
// Module name mapping to fix haste collision
|
// Module name mapping to fix haste collision
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
"^@/(.*)$": "<rootDir>/$1",
|
"^@/(.*)$": "<rootDir>/$1",
|
||||||
|
"^boneyard-js/react$": "<rootDir>/__mocks__/boneyard-js/react.tsx",
|
||||||
},
|
},
|
||||||
// Exclude problematic directories from haste
|
// Exclude problematic directories from haste
|
||||||
modulePathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/", "<rootDir>/e2e/"],
|
modulePathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/", "<rootDir>/e2e/"],
|
||||||
|
|||||||
Reference in New Issue
Block a user