-
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
cy.visit() Typescript promise chain error - Type 'Chainable<HTMLInputElement>' is missing the following properties #6206
Comments
I'm not aware of any additional constraints you have, but just in case: isn't that what you're looking for? cy.visit('./core/selectors/selectors-test-file.html')
.then(window$ => window$.document.getElementById('textInputID') as HTMLInputElement)
.should('have.property', 'value', ''); Or, since DOM elements with cy
.visit('./core/selectors/selectors-test-file.html')
.its('document.textInputID')
.should('have.property', 'value', ''); Alternatively, if you need to access let input: HTMLInputElement;
cy.visit('./core/selectors/selectors-test-file.html').then(window$ => {
input = window$.document.getElementById('textInputID') as HTMLInputElement;
}); (Cypress |
I use the Based on your comment above though, it sounds like this pattern will work: const loadInput = (callback) => {
cy.visit('./core/selectors/selectors-test-file.html').then(window$ => {
input = window$.document.getElementById('textInputID') as HTMLInputElement;
callback(input)
});
}
it("Should work", ()=> {
loadInput($input => {
expect($input.value).to.equal('')
})
}) |
I like the promise async/await syntax a lot more though. I switched to using cypress-promise to make my code cleaner. Based on the number of downloads, many other developers feel the same way. It has the annoying issue of triggering the warning though. NicholasBoll/cypress-promise#6 Is there a way that the warning can be suppressed if we choose that we would prefer to work with promises? |
Just to chime in here... We're using Cypress to validate our API - no UI involved, except for Cypress itself (to inspect requests). Our code often times has cypress-promise would enable that, and make our code MUCH more readable. But it would also create dozens of warnings in our console, and that's a non-starter. It would be nice to be have some way to suppress that warning. I'm tempted to make a fork of Cypress just to remove that warning... but that seems like a pretty extreme measure. |
It's a duplicate of #1417. |
Current behavior:
The following Typescript code produces an error:
The error message I get:
Desired behavior:
The
loadInput()
function should return a promise that later returns the HTML input DOM element.Versions
Work around
I worked around the issue by doing this:
But now Cypress is complaining about nesting
cy.visit()
inside a promise. It's just a warning though so I can ignore it.The text was updated successfully, but these errors were encountered: