.agents/skills/frontend-testing-setup/SKILL.md
Step-by-step instructions for scaffolding and maintaining the test environment with Jest and React Testing Library using a centralized approach.
npx skillsauth add filippovskii09/quize-audit Frontend Testing SetupInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
These step-by-step guidelines outline the optimal architecture for setting up and maintaining testing environments. We explicitly mandate using Jest and React Testing Library (RTL) with a clean, centralized configuration.
jest, @testing-library/react, @testing-library/user-event, @testing-library/jest-dom), якщо вони ще не встановлені.setupTest FileВ корені проекту (у директорії src/) створіть централізований файл setupTest.tsx (або .jsx).
У цьому файлі зберігатимуться:
jest-dom).ReactQuery, MemoryRouter, I18nProvider тощо).@testing-library/react.src/setupTest.tsx:import '@testing-library/jest-dom';
import React, { type ReactElement } from 'react';
import {
render as rtlRender,
renderHook as rtlRenderHook,
screen, waitFor, within, act, fireEvent, cleanup,
type RenderOptions, type RenderHookOptions
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { jest } from '@jest/globals';
// Імпортуйте необхідні провайдери вашого проекту
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MemoryRouter } from 'react-router-dom';
import { IntlProvider } from 'react-intl';
/**
* Common wrapper component for multiple context providers.
*/
const TestWrapper = ({ children, initialEntries = ['/'] }: any) => {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
return (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={initialEntries}>
<IntlProvider locale="en">
{children}
</IntlProvider>
</MemoryRouter>
</QueryClientProvider>
);
};
function render(ui: ReactElement, { initialEntries, ...options }: any = {}) {
return rtlRender(ui, { wrapper: (props) => <TestWrapper {...props} initialEntries={initialEntries} />, ...options });
}
function renderHook<Result, Props>(
callback: (initialProps: Props) => Result,
{ initialEntries, ...options }: any = {}
) {
return rtlRenderHook(callback, { wrapper: (props) => <TestWrapper {...props} initialEntries={initialEntries} />, ...options });
}
export {
render, renderHook, screen, waitFor, within, act, fireEvent, cleanup, userEvent, jest
};
@setupTestЦе єдиний файл, який буде підключатись майже в усі тести, тому зручно використовувати аліас @setupTest.
Додайте цей аліас у файли конфігурації:
В tsconfig.json (в блок paths):
"paths": {
"@setupTest": ["src/setupTest.tsx"]
}
В vite.config.ts:
resolve: {
alias: {
'@setupTest': path.resolve(__dirname, './src/setupTest.tsx'),
},
},
В усіх файлах тестів (*.spec.tsx чи *.test.tsx) використовуйте цей аліас. Категорично забороняється імпортувати render або screen напряму з @testing-library/react.
import { render, screen, userEvent } from '@setupTest';
// Ваші тести...
Додайте кавередж та всі збірки до ігнорування, а також налаштуйте Jest для використання setupTest і аліасу.
В .gitignore додайте:
coverage/
В jest.config.ts:
export default {
// ... інші конфігурації
setupFilesAfterEnv: ['<rootDir>/src/setupTest.tsx'],
moduleNameMapper: {
// Вкажіть аліас для jest:
'^@setupTest$': '<rootDir>/src/setupTest.tsx',
},
// Ігнорування папок, які не потрібно обробляти:
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/coverage/', 'src/setupTest.tsx'],
};
development
Domain skill for React internationalization setup with react-intl, locale switching, and typed i18n context. Use when adding new translations or extending locale behavior.
development
Domain skill for reusable typed React hooks used in business logic. Use when extending or validating shared hooks like local storage and pagination.
development
Reusable Prettier formatting recipe for TypeScript and frontend repositories. Use when enforcing consistent code style and integrating format checks in hooks.
tools
Declarative pre-commit framework recipe for polyglot repositories with stage-aware hooks (pre-commit and pre-push). Use when repositories need non-Node quality gates or mixed toolchains.