Fixtures
Mock data and API responses for end-to-end testing.
E2E Test Fixtures
Mock data and API responses for end-to-end testing.
What This Directory Contains
Test fixtures that provide predictable, realistic data for E2E tests. These fixtures allow tests to run quickly and reliably without depending on external APIs.
Why Fixtures Are Important
E2E tests need:
- Reliability: External APIs can be slow, rate-limited, or unavailable
- Speed: Mock responses are instantaneous
- Predictability: Same input always produces same output
- Offline capability: Tests work without network access
- Edge case testing: Easy to simulate errors and unusual responses
Files
api-mocks.ts
Intercepts NJ Geocoding API calls and returns mock responses.
How to Use
Setup API Mocking
import { setupApiMocks } from "./fixtures/api-mocks";
test.beforeEach(async ({ page }) => {
await setupApiMocks(page);
await page.goto("/lookup");
});
test("should display municipality", async ({ page }) => {
// API calls will be mocked automatically
await page
.getByRole("combobox", { name: /street/i })
.fill("323 Dr Martin Luther King Jr Blvd");
// ...
});
Simulate API Errors
import { setupApiMocksWithError } from "./fixtures/api-mocks";
test("should handle timeout", async ({ page }) => {
await setupApiMocksWithError(page, "timeout");
await page.goto("/lookup");
// Form submission will trigger timeout error
});
Available Mock Addresses
The following real NJ government addresses have mock responses:
| Address | Municipality | County |
|---|---|---|
| 323 Dr Martin Luther King Jr Blvd, Newark | Newark | Essex |
| 125 West State Street, Trenton | Trenton | Mercer |
| 83 Somerset Street, New Brunswick | New Brunswick | Middlesex |
| 354 Stockton Street, Princeton | Princeton | Mercer |
| 2039 John F Kennedy Boulevard, Jersey City | Jersey City | Hudson |
Available Error Simulations
| Error Type | Description |
|---|---|
timeout | Simulates API timeout (10 second delay) |
network | Simulates network failure |
empty | Returns empty candidates (address not found) |
Adding New Mock Data
- Add address to
MOCK_GEOCODE_RESPONSESobject - Include all required fields matching NJ API response structure
- Add corresponding suggestions to
MOCK_SUGGEST_RESPONSESif needed
export const MOCK_GEOCODE_RESPONSES = {
// Add new address
"100 Example Street, City Name": {
candidates: [
{
address: "100 EXAMPLE ST, CITY NAME, NJ, 00000",
location: { x: -74.0, y: 40.0 },
score: 100,
attributes: {
Zone: "City Name",
County: "County Name",
StAddr: "100 EXAMPLE ST",
City: "CITY NAME",
Postal: "00000",
},
},
],
spatialReference: { wkid: 4326, latestWkid: 4326 },
},
};
Related Documentation
../README.md- E2E testing overview../helpers/README.md- Form interaction helpers../../README.md- Test suite overview