From cea13c42354a9aef3ed7e89bf52f986bb3b5a41c Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 2 Nov 2020 16:23:40 -0500 Subject: [PATCH] docs(route2): document dynamic request aliasing --- source/api/commands/route2.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/api/commands/route2.md b/source/api/commands/route2.md index a0d564c433..36cb345256 100644 --- a/source/api/commands/route2.md +++ b/source/api/commands/route2.md @@ -205,6 +205,21 @@ cy.wait('@someRoute').its('response.statusCode').should('eq', 500) cy.wait('@someRoute').its('response.body').should('include', 'id') ``` +### Aliasing individual requests + +Aliases can be set on a per-request basis by setting the `alias` property of the intercepted request: + +```js +cy.route2('POST', '/graphql', (req) => { + if (req.body.includes('mutation')) { + req.alias = 'gqlMutation' + } +}) + +// assert that a matching request has been made +cy.wait('@gqlMutation') +``` + ## Stubbing a response ### With a string