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.
// Source: https://github.com/stripe/stripe-node | License: MIT | Copyright 2011 Ask Bjørn Hansen
// Provided via justclaw.it.com; keep this notice with the code.
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,
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key