Please add support for cy.request() and cy.route() as Custom Commands
When adding cy.request() or cy.route() as a custom command such as
Cypress.Commands.add("sellersignin",
cy.request({
method: 'POST',
url: '/api/user/whatever',
form: true,
body: {
identification: '[email protected]',
password: 'whatever'
}
}))
Cypress returns "must be within an "IT" command, regardless of if cy.sellersignin() is called in a test.
While there's a workaround in Adding this to the beginning of a bank of tests, It means that the code very quickly gets sloppy with adding requests for logins and logouts when a test needing verification that one users actions can be viewed (or not viewed) by another user.
Not allowing these types of commands in a custom command defeats the purpose of having custom commands.
Be able to assign a cy.route() command as a custom command
Cypress Version 3.1.2, OSX, All browsers
From your example code, you don't seem to be wrapping the cy.request() in a function expression, but rather calling it at the time of the Cypress.Commands.add definition.
Instead, do:
Cypress.Commands.add("sellersignin", () => {
cy.request({ method: 'POST', url: '/api/user/whatever', form: true, body: { identification: '[email protected]', password: 'whatever' } })
});
@dwelle suggestion is correct. Closing as resolved.
Most helpful comment
From your example code, you don't seem to be wrapping the
cy.request()in a function expression, but rather calling it at the time of theCypress.Commands.adddefinition.Instead, do: