react-testing
React component testing with React Testing Library + Vitest/Jest + MSW network mocking + axe accessibility assertions. Covers unit, integration, and component vs E2E decision boundary.
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 13
- Forks
- 1
01 前言 Front Matter
- name
- react-testing
- source
- https://github.com/affaan-m/ECC
- license
- MIT
- description
- React component testing with React Testing Library + Vitest/Jest + MSW network mocking + axe accessibility assertions. Covers unit, integration, and component vs E2E decision boundary.
03 SKILL.md 正文
React Testing
Test behavior, not implementation. Query by role/label, not CSS or test-id.
Trigger phrases: "test React component", "RTL", "React Testing Library", "write tests for component", "MSW mock", "accessibility test"
Core Principle
// ✅ Query as users perceive
const button = screen.getByRole('button', { name: /submit/i })
const input = screen.getByLabelText('Email address')
// ❌ Implementation details
screen.getByClassName('btn-primary')
screen.getByTestId('submit-btn')
Component Test Template
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
describe('LoginForm', () => {
it('calls onSubmit with credentials', async () => {
const onSubmit = vi.fn()
render(<LoginForm onSubmit={onSubmit} />)
await userEvent.type(screen.getByLabelText('Email'), 'a@b.com')
await userEvent.type(screen.getByLabelText('Password'), 'secret')
await userEvent.click(screen.getByRole('button', { name: /sign in/i }))
expect(onSubmit).toHaveBeenCalledWith({ email: 'a@b.com', password: 'secret' })
})
})
MSW Network Mocking
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
const server = setupServer(
http.get('/api/users', () => HttpResponse.json([{ id: 1, name: 'Alice' }])),
)
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
Accessibility Testing
import { axe, toHaveNoViolations } from 'jest-axe'
expect.extend(toHaveNoViolations)
it('has no a11y violations', async () => {
const { container } = render(<LoginForm onSubmit={vi.fn()} />)
expect(await axe(container)).toHaveNoViolations()
})
Component vs E2E Decision
| Test | Tool |
|---|---|
| Component renders + behaves | RTL |
| Network request handling | RTL + MSW |
| Full user flow across pages | Playwright |
| Visual regression | Playwright screenshots |
Async Patterns
// ✅ findBy* has built-in waitFor
const result = await screen.findByRole('status')
// ❌ Arbitrary timeouts
await new Promise(r => setTimeout(r, 1000))
Anti-Fake-Pass
❌ Testing internal state (useState calls) not user-visible behavior
❌ Not using userEvent.setup() — legacy fireEvent misses pointer events
❌ Mocking fetch globally instead of MSW — brittle, order-dependent
❌ Full DOM snapshot tests — any refactor breaks them
04 同仓库更多 Skills
openai--sentry--sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
ito-basket-compare
Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.
implementing-network-traffic-baselining
Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling
detecting-evasion-techniques-in-endpoint-logs
Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.
implementing-microsegmentation-with-guardicore
Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.
ramdisk-tmpfs-patterns
暂无简介