> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# mock

> Intercept a network route and return a custom response.

Requires exactly one URL matcher. `responseGenerator` is a JavaScript function
body evaluated for every match. It receives the captured `mock.request` (and
`mock.response` when `fetchOriginalResponse` is set) and returns the response
body.

## Parameters

| Parameter               | Type      | Required | Description                                                           |
| ----------------------- | --------- | -------- | --------------------------------------------------------------------- |
| `substring`             | `string`  | No       | Match URLs that contain this substring.                               |
| `glob`                  | `string`  | No       | Match URLs against a glob pattern.                                    |
| `regex`                 | `string`  | No       | Match URLs against a regular expression.                              |
| `domain`                | `string`  | No       | Match all URLs under the given domain.                                |
| `method`                | `string`  | No       | Restrict mocking to a specific HTTP method.                           |
| `responseGenerator`     | `string`  | Yes      | JavaScript expression that returns the response body.                 |
| `fetchOriginalResponse` | `boolean` | No       | Make the real request first and pass the response to the generator.   |
| `key`                   | `string`  | No       | Stable key for `removeRouteMock`.                                     |
| `saveAs`                | `string`  | No       | Name of the variable to write this step's return value to.            |
| `retries`               | `number`  | No       | Number of times to retry the step on failure before failing the test. |
| `skipped`               | `boolean` | No       | Skip this step at execution time.                                     |

## Examples

```yaml theme={null}
- mock:
    substring: /todos
    method: get
    responseGenerator: |-
      return new Response(
        JSON.stringify([
          { id: 1, title: "mocked" },
        ]),
        { status: 200, headers: { "content-type": "application/json" } }
      )
    fetchOriginalResponse: false
    key: TODOS_MOCK
```

```yaml theme={null}
- mock:
    domain: setcookie.net
    fetchOriginalResponse: true
    responseGenerator: |-
      mock.response.headers.set("Set-Cookie", "sessionId=a3fWa")
      return mock.response
```

## Related

* [Request mocking](/platforms/web/request-mocking)
* [Test format](/core-concepts/test-format)
