All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 13m30s
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
// src/tests/utils/renderWithProviders.tsx
|
|
import React, { ReactElement } from 'react';
|
|
import { render, RenderOptions } from '@testing-library/react';
|
|
import { AppProviders } from '../../providers/AppProviders';
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
interface ExtendedRenderOptions extends Omit<RenderOptions, 'wrapper'> {
|
|
initialEntries?: string[];
|
|
}
|
|
|
|
/**
|
|
* A custom render function that wraps the component with all application providers.
|
|
* This is useful for testing components that rely on context values (Auth, Modal, etc.).
|
|
*
|
|
* @param ui The component to render
|
|
* @param options Additional render options
|
|
* @returns The result of the render function
|
|
*/
|
|
export const renderWithProviders = (
|
|
ui: ReactElement,
|
|
options?: ExtendedRenderOptions,
|
|
) => {
|
|
const { initialEntries, ...renderOptions } = options || {};
|
|
// console.log('[renderWithProviders] Wrapping component with AppProviders context.');
|
|
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
<MemoryRouter initialEntries={initialEntries}>
|
|
<AppProviders>{children}</AppProviders>
|
|
</MemoryRouter>
|
|
);
|
|
return render(ui, { wrapper: Wrapper, ...renderOptions });
|
|
}; |