Creates a testable Stripe instance with a mock request sender, replacing the real HTTP layer to avoid global state pollution and enable request hooking in tests.
export const getMockStripe = (
config: Record<string, unknown>,
request: RequestSender['_request']
): Stripe => {
class MockRequestSender extends RequestSender {
_request(
method: string,
host: string | null,
path: string,
data: RequestData,
authenticator: RequestAuthenticator,
options: InternalRequestOptions = {} as any,
usage: Array<string>,
callback: RequestCallback,
requestDataProcessor: RequestDataProcessor | null = null
) {
return request(
method,
host,
path,
data,
authenticator,
options,
usage,
callback,
requestDataProcessor
);
}
}
// Provide a testable stripe instance
// That is, with mock-requests built in and hookable
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key