question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return types of Cypress commands

See original GitHub issue

What would you like?

It seems that Cypress.Chainable interface is not really used or required when yielding stuff from one command to another. A visual example:

Screenshot 2022-07-23 at 23 30 31

I’d imagine that in order to use .click() command a previous command needs to return proper type. Ideally compiler should complain about a command chain like this.

Ideally there should be possibility to use this at least with custom commands so that when I create something like cy.createItem() in my codebase, it should be easily identifiable if this returns a response body from API or a DOM element.

@marktnoonan told me I can tag @lmiller1990 on this 😂

Why is this needed?

No response

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Aug 17, 2022

I wonder if we just need to do a table/doc of all the different combinations that are possible, what we expect, and any edge cases, and re-assess how our types are organized/defined from a more high level… I am not sure how far we can get with incremental improvements. Starting with all DOM node related commands is a good idea. Getting type inference on commands that return DOM elements would be a huge productivity boost.

1reaction
filiphriccommented, Aug 17, 2022

I’m thinking maybe a good place to start are commands that we definitely know will return an HTML element, like eq(), .filter(), .parent() etc. and then maybe pair them with all the .should() assertion that only work for DOM elements? It’s not very “rounded feature”, but could maybe work as an initial proof of concept.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Commands - Cypress Documentation
Cypress comes with its own API for creating custom commands and overwriting existing commands. The built in Cypress commands use the very same...
Read more >
How to get returned value from custom commands ? (Cypress ...
To do this I'm using wrap() to return a Chainable containing the value I want to return. Since wrap() is returning a Cypress....
Read more >
Cypress Return Values, Variables, and Aliases - YouTube
In today's video, we discuss return values, variables, and aliases in Cypress at a high level. This covers closures, the then command, ...
Read more >
Return Cypress Chain - YouTube
If you refactor the test code, remember to return the Cypress command chain from the utility functions. This lets you attach more commands...
Read more >
How to return a list of objects from Cypress Custom ... - GitHub
Chainable<JQuery<expectedData[]>> // ??? not sure what return type should be given here. } } } Cypress.Commands.add('getTestDataFromDynamoDB', ({locale, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found