-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
Create reusable mocking utilities to reduce code duplication in tests and improve test maintainability across the codebase.
Work Required
- Create Mock Page Utility: Add
test/utils/mockPage.jsfor Playwright page mocking - Create HTTP Mock Utility: Add
test/utils/httpMocks.jsfor external API mocking - Refactor Existing Tests: Update existing tests to use new utilities
- Document Usage: Add documentation for utility usage patterns
Implementation Details
Based on existing test patterns and upcoming test needs:
test/utils/mockPage.js
- Mock Playwright page object for capture system tests
- Provide common page methods:
evaluate(),waitForTimeout(),screenshot() - Mock page properties and events for visual detector tests
- Support method chaining and Promise-based APIs
test/utils/httpMocks.js
- Mock axios/fetch for external API calls in stocks/weather modules
- Provide utilities for mocking HTTP responses, timeouts, errors
- Support rate limiting simulation for API testing
- Include common response patterns for external services
Current Test Patterns to Improve
From existing tests:
test/templates.validation.api.test.js- Uses supertest for API testing- Future capture system tests will need page mocking
- Future stocks/weather tests will need HTTP mocking
Mock Patterns Needed
Page Mocking
const mockPage = createMockPage({
evaluate: jest.fn(),
waitForTimeout: jest.fn(),
screenshot: jest.fn()
});HTTP Mocking
const httpMock = createHttpMock()
.get('/api/external')
.reply(200, { data: 'test' });Files to Create
test/utils/mockPage.js- Playwright page mocking utilitytest/utils/httpMocks.js- HTTP request mocking utilitytest/utils/index.js- Barrel export for utilities
Usage Guidelines
- Keep utilities focused and composable
- Provide clear documentation and examples
- Follow Jest mocking best practices
- Make utilities easy to extend for specific use cases
Acceptance Criteria
- Duplicate mock code is reduced across test files
- New utilities are adopted in new tests
- Existing tests can be refactored to use utilities where appropriate
- Utilities are well-documented with usage examples
- Mock utilities support common testing patterns in the codebase
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels