mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-20 21:23:10 +03:00
Test Helpers
This directory contains helper utilities for testing to keep test files clean and maintainable.
Files
http-mocks.ts
Contains mock implementations for external HTTP endpoints used in testing:
-
httpbin.org mocks: Comprehensive mocks for HTTP diagnostics testing including:
- Compression support (gzip, brotli, deflate)
- Header testing
- Redirect tracing
- Cookie handling
- Timeout simulation
- Status code testing
-
example.com mocks: Basic HTML responses for simple HTTP testing
Usage
These helpers are automatically imported in tests/setup.ts and used by the MSW server to intercept external API calls during testing.
Benefits
- CI/CD Reliability: No external dependencies that could fail or be slow
- Deterministic Tests: Consistent, predictable responses
- Fast Execution: Local mocks are much faster than real HTTP calls
- Clean Test Code: Complex mock logic is extracted from test files
- Reusable: Same mocks can be used across multiple test files
Maintenance
When adding new external API dependencies to the application:
- Add corresponding mocks to the appropriate helper file
- Import and use in
tests/setup.ts - Ensure mocks accurately simulate the real API behavior
- Add appropriate error suppression patterns in setup.ts if needed