Skip to content

Commit

Permalink
docs: add request fixture description
Browse files Browse the repository at this point in the history
  • Loading branch information
Crustum7 committed Sep 29, 2023
1 parent 1459cce commit ffa7961
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/api/commands/request.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Make an HTTP request.
```javascript
cy.request(url)
cy.request(url, body)
cy.request(url, fixture)
cy.request(method, url)
cy.request(method, url, body)
cy.request(method, url, fixture)
cy.request(options)
```

Expand Down Expand Up @@ -66,6 +68,9 @@ cy.request('seed/admin') // URL is http://localhost:1234/seed/admin
A request `body` to be sent in the request. Cypress sets the `Accepts` request
header and serializes the response body by the `encoding` option.

**<Icon name="angle-right" /> fixture** **_(String)_**
A string specifying a fixture. The data in the fixture is used in the request `body`. The string is prefixed with `'fx:'` followed by the name of the fixture.

**<Icon name="angle-right" /> method** **_(String)_**

Make a request using a specific method. If no method is defined, Cypress uses
Expand Down Expand Up @@ -196,6 +201,25 @@ cy.request('POST', 'http://localhost:8888/users/admin', { name: 'Jane' }).then(
)
```

#### Send a `POST` request with a fixture as the JSON body

```javascript
cy.request('POST', 'http://localhost:8888/users/admin', 'fx:person').then(
(response) => {
// response.body is automatically serialized into JSON
expect(response.body).to.have.property('name', 'Jane') // true
}
)
```

`person.json`

```json
{
name: 'Jane'
}
```

### Options

#### Request a page while disabling auto redirect
Expand Down

0 comments on commit ffa7961

Please sign in to comment.