---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk/testing/functions/createMockFetch.md
---
[Reference](../../../../index.md) / [@getenginex/sdk/testing](../index.md) / createMockFetch

# createMockFetch()

> **createMockFetch**(`options?`): {(`input`, `init?`): `Promise`<`Response`>; (`input`, `init?`): `Promise`<`Response`>; }

Creates a mock `fetch` for `createEnginexClient({ fetch })`, with realistic default responses
for the public config (`GET /config`, `/config/branding`, `/config/products`,
`/config/sportsbook`, `/support/config`), sign-up, login, refresh, logout, profile (`GET`/`PUT
/me`, `GET /me/sessions`, `DELETE /me/sessions/current` and `/mock-session-2`) and wallet (balance,
statement, PIX deposit, withdrawal with or without OTP and PIX keys) and KYC (`GET /kyc/status` and the multipart
upload of `POST /kyc/documents`, which moves the status to `pending`). State (profile, balance,
deposits, withdrawals, keys, KYC) is in memory, per mock: a withdrawal debits the balance and the same `Idempotency-Key` repeats
the first response, as at the gateway. A deposit stays pending until [markDepositPaid](markDepositPaid.md).
All of them match the SDK's real schemas, even with `validation: 'strict'`. With no new
dependency (no MSW): it is just a `fetch` function routed by method and path.

In Node (Vitest, Jest, scripts) the client still needs an absolute `baseUrl` and `tenantHost`
(placeholder values will do); without them the first request rejects with `CONFIGURATION_ERROR`. In the
browser both are optional.

## Parameters

### options?

[`MockFetchOptions`](../interfaces/MockFetchOptions.md) = `{}`

## Returns

> (`input`, `init?`): `Promise`<`Response`>

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

### Parameters

#### input

`URL` | `RequestInfo`

#### init?

`RequestInit`

### Returns

`Promise`<`Response`>

> (`input`, `init?`): `Promise`<`Response`>

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

### Parameters

#### input

`string` | `URL` | `Request`

#### init?

`RequestInit`

### Returns

`Promise`<`Response`>

## Examples

```ts
import { createEnginexClient } from '@getenginex/sdk'
import { createMockFetch } from '@getenginex/sdk/testing'

const enginex = createEnginexClient({
  baseUrl: 'https://gateway.test', // in Node: absolute baseUrl + tenantHost (in the browser, optional)
  tenantHost: 'casino.test',
  fetch: createMockFetch(),
})
const config = await enginex.config.get()
await enginex.auth.login({ email: 'ana@exemplo.com', password: 'Senha@123' })
```

```ts
// Overriding a route to test an error path
import { createMockFetch, fail } from '@getenginex/sdk/testing'

const fetch = createMockFetch({
  routes: { 'POST /api/v1/auth/login': () => fail(401, 'INVALID_CREDENTIALS', 'wrong password') },
})
```
