-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add assertions to '.select()' doc #216
Comments
Hi Jennifer, I am a newbie to open source and wondering if I can work on this issue? If yes where's a good place to start? |
Hey @ootsuka, the document that needs to be updated can be found here: https://github.com/cypress-io/cypress-documentation/blob/develop/source/api/commands/select.md which is the source for this page: https://docs.cypress.io/api/commands/select.html I think we just wanted the current Examples updated to include assertions like instead of this: cy.get('select').select('apples') It would show this: cy.get('select').select('apples')
.should('have.value', '456') |
Thank you. I am trying to include the assertions but I am having trouble with
Do you mind share how you would do the assertion for this one? |
@ootsuka This one definitely is trickier! The value of a select with multiple options selected will be an array of the option's values. So, we'll need to pull out the value first using We'll also need to use the cy.get('.action-select-multiple')
.select(['apples', 'oranges', 'bananas']).invoke('val')
.should('deep.equal', ['456', '457', '458']) |
Yes. I was trying to go for the deep equal but could not get the value cause I did not know the invoke(‘val’). |
The question you have to ask yourself is why add an assertion after doing a However, if you aren't modifying anything, then you don't need an assertion because you can assume Cypress is doing the right thing. If you tell Cypress to select something that's an invalid value - it will already throw an error. So if the |
@brian-mann This isn't really a terribly useful real use case, it's more of a good place to outline how to assert on select values, because people were having a hard time writing the assertions. Although, I generally test things like this because of how my |
Right if you are modifying the value then it makes sense to add an assertion that the right stuff was selected. I'm pretty sure you can just do |
No, you can't just write |
We control the Instead of the expression: Doing it that way ends up being the same thing as |
@brian-mann I think that's a good idea. @jennifer-shehane do you think it's the right way to do it? |
Can this issue be closed? |
See cypress-io/cypress-example-kitchensink#23
The text was updated successfully, but these errors were encountered: