NJ Municipality Lookup
CodebaseTestsE2e

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:

  1. Reliability: External APIs can be slow, rate-limited, or unavailable
  2. Speed: Mock responses are instantaneous
  3. Predictability: Same input always produces same output
  4. Offline capability: Tests work without network access
  5. 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:

AddressMunicipalityCounty
323 Dr Martin Luther King Jr Blvd, NewarkNewarkEssex
125 West State Street, TrentonTrentonMercer
83 Somerset Street, New BrunswickNew BrunswickMiddlesex
354 Stockton Street, PrincetonPrincetonMercer
2039 John F Kennedy Boulevard, Jersey CityJersey CityHudson

Available Error Simulations

Error TypeDescription
timeoutSimulates API timeout (10 second delay)
networkSimulates network failure
emptyReturns empty candidates (address not found)

Adding New Mock Data

  1. Add address to MOCK_GEOCODE_RESPONSES object
  2. Include all required fields matching NJ API response structure
  3. Add corresponding suggestions to MOCK_SUGGEST_RESPONSES if 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 },
  },
};

On this page