Object is of type 'unknown' for custom command #22973
Answered
by
jjhelguero
jeansberg
asked this question in
Questions and Help
-
After upgrading to Cypress 10, tests using custom commands are failing due to TS2571: Object is of type 'unknown'. In VS code I can see that 'subject' in the subject.get call is marked red, because it is of type 'unknown'. Is there something wrong with the typing or should this command be rewritten somehow? Grateful for any help 🙏
|
Beta Was this translation helpful? Give feedback.
Answered by
jjhelguero
Jul 29, 2022
Replies: 1 comment 1 reply
-
Looks like you are not wrapping the previous subject passed into your custom command. It seems from your definition, the subject will be a jQuery element. Maybe that is the reason? Cypress.Commands.add(
"getSelect2OptionByText",
{ prevSubject: "optional" },
(subject, text) =>
subject
? cy.wrap(subject).get(".select2-results").contains(text)
: cy.get(".select2-results").contains(text)
); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jeansberg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you are not wrapping the previous subject passed into your custom command. It seems from your definition, the subject will be a jQuery element. Maybe that is the reason?