estrategia-de-testes-frontend

Guides unit, integration, and E2E testing for a React TypeScript chess frontend.

Updated Jan 28, 2024
One-click install
npx skills add https://github.com/Thiago-Cruz-eng/KrockSide --skill estrategia-de-testes-frontend-thiago-cruz-eng
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: estrategia-de-testes-frontend
Source: https://github.com/Thiago-Cruz-eng/KrockSide/tree/main/.agents/skills/estrategia-de-testes-frontend
Command: npx skills add https://github.com/Thiago-Cruz-eng/KrockSide --skill estrategia-de-testes-frontend-thiago-cruz-eng

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Frontend tests in this React + TypeScript chess app often fail for the wrong reasons: mocks that mirror wrong backend routes, SignalR hub connections attempted in unit tests, unstable CSS selectors, and session state leaking between cases. This Skill provides the canonical recipes and conventions for testing at all three levels so tests catch real bugs instead of confirming them. ## Core Features & Use Cases - Three-level test strategy: Unit tests with Jest, React Testing Library, createFakeHub, and axios-mock-adapter; integration tests with MSW v1; E2E tests with Playwright and page.route. - SignalR hub testing recipes: Use createFakeHub with HubTestProvider, emit server events inside act(), and throw on unexpected hub methods for clear failure messages. - Known-trap documentation: Warns that current MSW handlers and E2E routes mock nonexistent backend endpoints (/create, /get/:id, /refresh), so route fixes must update mocks in the same commit. - Use Case: Before writing the first test for a new component or hook, follow the recipes to pick the lowest test level, list scenarios (success, server refusal, invalid input, disconnected hub), and write the failing test first. ## Quick Start Ask the assistant to write a unit test for a component that talks to the SignalR hub using createFakeHub and the conventions from this testing strategy.

Frequently Asked Questions about estrategia-de-testes-frontend

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a React component that uses a SignalR hub?

Use createFakeHub from the test-utils hub module and wrap the component in HubTestProvider. Set hub.setInvoke to return canned responses per method, throw on unexpected methods, and emit server events inside act() so state updates flush correctly.

How to mock REST API calls in React unit tests with axios?

Use axios-mock-adapter on an axios instance created by createApi, then define replies with mock.onPost and similar. Test the Authorization interceptor explicitly by seeding a token and asserting the header in mock.history.

What is the difference between MSW integration tests and Playwright E2E tests?

MSW v1 integration tests run in Jest with jsdom and intercept REST calls at the network layer via server.listen. Playwright E2E tests run a real browser against the dev server and mock REST with page.route, but cannot practically mock the SignalR WebSocket hub.

Why do my tests pass but the app is broken against the real backend?

The mocks may mirror wrong routes: handlers.ts mocks /create, /get/:id, and /refresh, which do not exist on the backend. When fixing a route in userApi, fix the mock in the same commit so tests validate real behavior.

Can Playwright page.route mock SignalR WebSocket connections?

No, page.route cannot practically mock SignalR because it uses negotiate plus WebSocket transport. E2E tests should cover login, navigation, and rendering; in-progress game flows belong in integration tests with createFakeHub.

Why do tests pass alone but fail when run in the full suite?

Session state leaking between cases is the most common cause. Clear localStorage and sessionStorage in beforeEach, and avoid empty waitFor calls or setTimeout by waiting on assertions like findByText instead.