11# Testing Guide
22
3- This document provides a comprehensive guide for testing the ROFL App application.
3+ This document provides a comprehensive guide for testing the ROFL App
4+ application.
45
56## Table of Contents
67
@@ -27,7 +28,8 @@ We use the following testing tools:
2728
2829### Installation
2930
30- Testing dependencies are already included in ` package.json ` . After cloning the repository:
31+ Testing dependencies are already included in ` package.json ` . After cloning
32+ the repository:
3133
3234``` bash
3335yarn install
@@ -62,7 +64,9 @@ yarn test:run
6264yarn test:coverage
6365```
6466
65- This generates a coverage report in the ` coverage/ ` directory with multiple formats:
67+ This generates a coverage report in the ` coverage/ ` directory with multiple
68+ formats:
69+
6670- HTML report: ` coverage/index.html `
6771- JSON: ` coverage/coverage-final.json `
6872- LCOV: ` coverage/lcov.info `
@@ -79,7 +83,8 @@ This launches the Vitest UI for an interactive test experience.
7983
8084### Component Tests
8185
82- Use the custom ` render ` function from ` test-utils.tsx ` which includes all necessary providers:
86+ Use the custom ` render ` function from ` test-utils.tsx ` which includes all
87+ necessary providers:
8388
8489``` tsx
8590import { render , screen } from ' @/test/test-utils'
@@ -176,6 +181,7 @@ describe('myUtility', () => {
176181 - Avoid testing internal state or methods
177182
1781832 . ** Write descriptive test names**
184+
179185 ``` tsx
180186 // Good
181187 it (' should display error message when API call fails' )
@@ -185,6 +191,7 @@ describe('myUtility', () => {
185191 ```
186192
1871933 . ** Use appropriate assertions**
194+
188195 ``` tsx
189196 // Good
190197 expect (screen .getByRole (' button' , { name: ' Submit' })).toBeInTheDocument ()
@@ -204,6 +211,7 @@ describe('myUtility', () => {
204211### Component Testing
205212
2062131 . ** Test user interactions**
214+
207215 ``` tsx
208216 import { render , screen } from ' @testing-library/react'
209217 import userEvent from ' @testing-library/user-event'
@@ -229,6 +237,7 @@ describe('myUtility', () => {
229237 - Empty state
230238
2312393 . ** Test accessibility**
240+
232241 ``` tsx
233242 it (' should be accessible' , () => {
234243 render (<MyComponent />)
@@ -239,6 +248,7 @@ describe('myUtility', () => {
239248### Hook Testing
240249
2412501 . ** Test hook behavior**
251+
242252 ``` tsx
243253 it (' should update state when action is called' , () => {
244254 const { result } = renderHook (() => useMyHook ())
@@ -252,6 +262,7 @@ describe('myUtility', () => {
252262 ```
253263
2542642 . ** Test error handling**
265+
255266 ``` tsx
256267 it (' should handle errors gracefully' , async () => {
257268 const { result } = renderHook (() => useMyHook ())
@@ -350,6 +361,7 @@ The ROFL app has comprehensive test coverage exceeding industry standards:
350361### Coverage Thresholds
351362
352363Configured in ` vitest.config.ts ` :
364+
353365- Statements: 80%
354366- Branches: 75%
355367- Functions: 80%
@@ -372,14 +384,16 @@ xdg-open coverage/index.html # Linux
372384start coverage/index.html # Windows
373385```
374386
375-
376387### CI/CD Integration
377388
378- Coverage reports are automatically generated in CI/CD and uploaded as artifacts. Failed coverage thresholds will cause the build to fail.
389+ Coverage reports are automatically generated in CI/CD and uploaded as
390+ artifacts. Failed coverage thresholds will cause the build to fail.
379391
380392## Resources
381393
382394- [ Vitest Documentation] ( https://vitest.dev/ )
383395- [ React Testing Library] ( https://testing-library.com/react )
384396- [ MSW Documentation] ( https://mswjs.io/ )
385- - [ Testing Best Practices] ( https://kentcdodds.com/blog/common-mistakes-with-react-testing-library )
397+ - [ Testing Best Practices] [ best-practices ]
398+
399+ [ best-practices ] : https://kentcdodds.com/blog/common-mistakes-with-react-testing-library
0 commit comments