From ffa7961e2b80c587b93b4769bc47a2b545df018e Mon Sep 17 00:00:00 2001 From: Martin Jonson Date: Fri, 29 Sep 2023 09:21:11 +0200 Subject: [PATCH] docs: add request fixture description --- docs/api/commands/request.mdx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/api/commands/request.mdx b/docs/api/commands/request.mdx index 0a3c780ff8b..560efc10561 100644 --- a/docs/api/commands/request.mdx +++ b/docs/api/commands/request.mdx @@ -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) ``` @@ -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. +** 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. + ** method** **_(String)_** Make a request using a specific method. If no method is defined, Cypress uses @@ -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