returning a promise in a custom command should throw
See original GitHub issueYou cannot return a 3rd party promise from a custom command because this breaks the chaining between cypress commands. This is because the .then
methods are not the same.
It is an anti-pattern anyway because all cypress commands are promises.
For instance doing this:
Cypress.addParentCommand('login', function (email, password) {
return new Cypress.Promise((resolve) => {
cy.request({
method: 'POST',
url: '/login',
body: {email, password}
})
.then(result => {
resolve(result.body);
})
})
})
…can simply be rewritten as:
Cypress.addParentCommand('login', function (email, password) {
cy.request({
method: 'POST',
url: '/login',
body: {email, password}
})
.its("body")
})
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
How to return a promise from a Cypress custom command in ...
My custom command returns a Promise , which Cypress automatically handles and converts to a Cypress.Chainable , but typescript doesn't know ...
Read more >Cypress.Promise
Cypress is promise aware so if you return a promise from inside of commands like .then() , Cypress will not continue until those...
Read more >Promise.prototype.then() - JavaScript - MDN Web Docs
Returns a new Promise immediately. This new promise is always pending when returned, regardless of the current promise's status. One of the ...
Read more >Error handling with promises - The Modern JavaScript Tutorial
In the task an error is thrown form inside the promise and promise is never settled neither with a resolve nor reject. The...
Read more >Custom Commands - WebdriverIO
If the promise gets rejected, the command will throw an error. import got from 'got' browser.addCommand('makeRequest', async (url) => { return ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Browsers have no notion of
require
. Browsers must have a build process to parse the dependency tree and generate JS files. Cypress does this withbrowserify
or you can swap this out withwebpack
.You cannot import Meteor that way because it would create a whole new instance which has nothing to do with the Meteor instance your app is using.
In order to access the Meteor in your application is the same way you’d access it from the dev tools - you just set it on
window
and then access it withcy.window().then((win) => win.Meteor )
@panneerselvamc Can you include the test code you’ve written where you call the function?