dev-proPRO
OverviewLộ Trình HọcPhỏng VấnAI System
dev-pro— Thực chiến Frontend React, Next.js & Luyện phỏng vấn
contact@dev-pro.online•Code thật. Phỏng vấn thật.
Seri React Mastery8 Lộ trình · Sandbox
Seri React Mastery
8 tracks
T01
React Core Foundations0/7 hoàn thành
T02
React Hooks Mastery0/5 hoàn thành
T03
React Component Architecture & Forms0/4 hoàn thành
T04
React & Compiler: Modern Path0/4 hoàn thành
T05
Form Engineering: RHF + Zod + Server Actions0/2 hoàn thành
T06
Advanced React Performance Patterns0/4 hoàn thành
T07
Enterprise React Testing & Production Readiness0/5 hoàn thành
  • Bài học (5)
  • Tư Duy Testing Chuẩn với Vitest & React Testing Library (RTL)18m•intermediate
  • Mocking Tầng Mạng với MSW (Mock Service Worker)20m•advanced
  • Kiểm Thử Custom Hooks & Zustand Store Độc Lập18m•intermediate
  • Accessibility (a11y) & Kiến Trúc Chịu Lỗi (Error Resilience)20m•advanced
  • Playwright E2E: Kiểm Thử Critical User Journeys24m•advanced
T08
Production Capstone: TeamBoard0/1 hoàn thành
Tiến độ React0/32 bài
Enterprise React Testing & Production Readiness
intermediate
18 phút
#Testing
#Vitest
#React Testing Library
#Best Practices

Tư Duy Testing Chuẩn với Vitest & React Testing Library (RTL)

Nguyên lý 'The more your tests resemble the way your software is used, the more confidence they can give you' và quy tắc chọn Query.

Core Mental Model

Đừng test cách code hoạt động bên trong (Implementation Details như state nội bộ hay tên biến), hãy test cách người dùng tương tác với giao diện (Click nút, gõ phím, nhìn thấy thông báo).

Key Takeaways & Principles

Quy tắc ưu tiên Query của RTL: `getByRole` (khuyến nghị số 1) -> `getByLabelText` -> `getByPlaceholderText` -> `getByText` -> `getByTestId` (chỉ dùng khi không còn cách khác).
Sử dụng `@testing-library/user-event` thay vì `fireEvent` để mô phỏng chính xác các chuỗi sự kiện thật của người dùng (hover, focus, keydown, keyup).
Tránh lạm dụng `shallow rendering` hoặc kiểm tra trực tiếp state nội bộ của component.