-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Provide strong types for 'invoke' command (#4022) #4907
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
Conversation
We don't consider type changes as breaking changes since the typescript checks can always be disabled. |
8157e28
to
3607df0
Compare
* | ||
* @see https://on.cypress.io/invoke | ||
*/ | ||
invoke(functionName: keyof Subject, ...args: any[]): Chainable<Subject> // don't have a way to express return types yet | ||
invoke< | ||
TActualSubject extends (Subject extends Node | Node[] ? JQuery<Subject> : Subject), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading through #806 (comment) and looking at the implementation of invoke
, I added handling for the jQuery wrapping invoke
does on its inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an example here to the jsdoc for the user to understand the API method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a couple examples based on the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good now
hmm, seems the types of arguments to jQuery element are too strict, these tests in Kitchensink are failing https://circleci.com/gh/cypress-io/cypress/144563
where the test is simply cy.get('.trigger-input-range')
.invoke('val', 25) |
I will revert the merged commit and will reopen the issue, don't want to release a breaking type change. Seems like the type is close, but stops at a single argument there |
…io#4907) * add strong return type to 'invoke' command * refactor invoke for clarity. use dtslint tests * add strong args types using typescript 3.0+ features * handle invoke's jquery wrapping of its input * move invoke tests to namespace * add example to jsdocs of 'invoke'
…ypress-io#4907)" This reverts commit 15685db. The type for `invoke` command seems to break jQuery method that take an argument like ```js cy.get('.trigger-input-range') .invoke('val', 25) ```
Closes #4022
Provides strong typing for arguments and return type of
invoke
command. Also ensuresfunctionName
is the key of a function on theSubject
.Since typing becomes more strict, this is technically a breaking change, but isn't considered a big deal (see #4907 (comment))
Pre-merge Tasks