Files
portfolio/jest.setup.ts
denshooter a5e5425c33
Some checks failed
CI/CD Pipeline (Using Gitea Variables & Secrets) / production (push) Failing after 8m59s
Test Gitea Variables and Secrets / test-variables (push) Successful in 3s
Fix ESLint error in jest.setup.ts
- Change @ts-ignore to @ts-expect-error as required by ESLint
- Simplify React.act mock to avoid TypeScript complexity
- Ensures linting passes in pre-push checks
2025-10-15 16:10:21 +02:00

65 lines
2.1 KiB
TypeScript

import 'whatwg-fetch';
import React from "react";
import { render } from '@testing-library/react';
import { ToastProvider } from '@/components/Toast';
// Fix for React production builds in testing
// Mock React's act function for production builds
if (process.env.NODE_ENV === 'production') {
// Override React.act for production builds
const originalAct = React.act;
if (!originalAct) {
// @ts-expect-error - Mock for production builds
React.act = (callback: () => void) => {
callback();
};
}
// Also mock the act function from react-dom/test-utils
// This is handled by Jest's module resolution
}
// Mock react-responsive-masonry
jest.mock("react-responsive-masonry", () => ({
__esModule: true,
default: ({ children }: { children: React.ReactNode }) =>
React.createElement("div", null, children),
get ResponsiveMasonry() {
const ResponsiveMasonryComponent = ({ children }: { children: React.ReactNode }) =>
React.createElement("div", null, children);
ResponsiveMasonryComponent.displayName = 'ResponsiveMasonry';
return ResponsiveMasonryComponent;
},
}));
// Mock next/link
jest.mock('next/link', () => {
const LinkComponent = ({ children }: { children: React.ReactNode }) => children;
LinkComponent.displayName = 'Link';
return LinkComponent;
});
// Mock next/image
jest.mock('next/image', () => {
const ImageComponent = ({ src, alt, fill, priority, ...props }: Record<string, unknown>) => {
// Convert boolean props to strings for DOM compatibility
const domProps: Record<string, unknown> = { src, alt };
if (fill) domProps.style = { width: '100%', height: '100%', objectFit: 'cover' };
if (priority) domProps.loading = 'eager';
return React.createElement('img', { ...domProps, ...props });
};
ImageComponent.displayName = 'Image';
return ImageComponent;
});
// Custom render function with ToastProvider
const customRender = (ui: React.ReactElement, options = {}) =>
render(ui, {
wrapper: ({ children }) => React.createElement(ToastProvider, null, children),
...options,
});
// Re-export everything
export * from '@testing-library/react';
export { customRender as render };