2 min read
Record a fixture
Capture one real sandbox response and save it. Your test then serves that fixture instead of calling out:
import { vi } from 'vitest';
import productsFixture from './fixtures/products.json';
vi.stubGlobal('fetch', vi.fn(async () => new Response(
JSON.stringify(productsFixture), { status: 200 },
)));
Keep fixtures fresh
Refresh fixtures from the sandbox on a schedule so they don't drift from the real contract. A weekly job that re-records and diffs is enough to catch breaking changes early.
Frequently asked questions
Mock or hit the sandbox?
Mock in unit tests for speed and isolation; hit the sandbox in a smaller set of integration tests to catch contract drift. Use both.
How do I stop fixtures going stale?
Automate re-recording from the sandbox and fail the job if the shape changed. That way your mocks track the real API.
Related reading

Quickstart: Test your integration against the sandbox
The sandbox returns deterministic data, so you can assert on exact values in CI without your tests flaking…
Read →
Quickstart: handle Credicorp API error responses
Every Credicorp API error uses the same envelope: { error: { type, code, message, request_id } }. Branch on…
Read →
Quickstart: choose the right base URL — sandbox vs production
Every Credicorp API integration should read its base host from configuration, never hard-code it. Development…
Read →
Quickstart: add timeouts and retries to a Node.js API client
A production API client needs a timeout and a retry policy. In Node, an AbortController bounds every request…
Read →Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.