Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add request fixture description #5508

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/api/commands/request.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ globally in [configuration](/guides/references/configuration).
| `method` | `GET` | The HTTP method to use in the request |
| `auth` | `null` | Adds Authorization headers. [Accepts these options.](https://github.com/request/request#http-authentication) |
| `body` | `null` | Body to send along with the request |
| `fixture` | `null` | Content of fixture used as body in the request. Cannot be combined with body |
| `failOnStatusCode` | `true` | Whether to fail on response codes other than `2xx` and `3xx` |
| `followRedirect` | `true` | Whether to automatically follow redirects |
| `form` | `false` | Whether to convert the `body` values to URL encoded content and set the `x-www-form-urlencoded` header |
Expand Down Expand Up @@ -276,6 +277,26 @@ cy.request({
cy.getCookie('cypress-session-cookie').should('exist')
```

#### Send a `POST` request with fixture content as body

```javascript
cy.request({
method: 'POST',
url: 'http://localhost:8888/users/admin',
fixture: 'person',
}).then((response) => {
expect(response.body).to.have.property('name', 'Jane')
})
```

`person.json`

```json
{
"name": "Jane"
}
```

#### Using `cy.request()` for HTML Forms

:::info
Expand Down