-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request cy.all to work with multiple commands in parallel #8719
Comments
Hi Jessica sry it could be that I've choosen the wrong issue template. Could you reassign and delete labels as you see fit? |
Absolutely required I'd say. I stumbled on this repo. However it doesn't work when I try it with fixtures. |
Whats the status on this task? This would be great! Can't wait to see this in changelog! |
Any updates here. |
Just wanted to leave this solution here for anyone interested (mixture of a few ideas). I have a use case where I needed to assert that subtotal + tip + tax = order total. The two challenges for testing here are:
To assert that these values add up, I need all 4 Cypress results present. This normally forces me to nest 4 levels of // cypress/support/commands.js
/**
* @param cypressCommandFns An array of functions that return Cypress commands
* @returns A Cypress chainable whose `.then()` passes an array of jQuery-wrapped DOM nodes
*/
Cypress.Commands.add('all', (cypressCommandsFns) =>
cypressCommandsFns.reduce(
(results, command) =>
results.then((bucket) => command().then((res) => [...bucket, res])),
cy.wrap([])
)
)
// my-test.spec.js
cy.all([
// Testing Library syntax
() => cy.findByRole('row', { name: /sub-total/i }),
() => cy.findByRole('row', { name: /estimated tax/i }),
() => cy.findByRole('row', { name: /tip/i }),
() => cy.findByRole('row', { name: /order total/i }),
]).then(([$subtotal, $tax, $tip, $total]) => {
... make sure values add up
}) Something to note: this strategy requires passing in functions that return Cypress commands. Hopefully this helps anyone struggling with this kind of testing challenge! |
@manuscriptmastr you probably can write the above test using the following solution https://cypresstips.substack.com/p/use-aliases-to-avoid-pyramid-of-callbacks |
@bahmutov Thanks for posting! Definitely see this working (and I love that it's the same use case 😃 ). TBH I don't love |
Just to confirm, @bahmutov had the ideal answer. As long as we can predict the aliases we will bind, there is no need to wait for all promises; just let Cypress fulfill them serially, and then "remember" all predicted aliases inside a |
Summary
Sometimes you want to work with multiple cypress commands but want to wait for all comands to finish before proceeding with another task
Current behavior
currently you have to chain these commands and pass the fetched data from promiselike to promiselike.
Desired behavior
like Bluebirds props method or my favorite
we could aggregate all comand responses into one object with cy.all
Relates to: #915
The text was updated successfully, but these errors were encountered: