-
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
fix: make component derived info not throw #24571
Conversation
Thanks for taking the time to open a PR!
|
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.
No hard blockers but some questions and ideas
@@ -108,7 +108,7 @@ export const makeMountFn = ( | |||
consoleProps: () => { | |||
return { | |||
// @ts-ignore protect the use of jsx functional components use ReactNode | |||
props: jsx.props, | |||
props: jsx?.props, |
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.
I think React defaults to an empty object for no props?
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.
Maybe when creating the component but jsx
here is just the first argument to mount
, so passing cy.mount(null)
would throw. I know it doesn't make sense to do that, but the types allow it and React doesn't throw so I thought I'd be safe here.
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! |
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
User facing changelog
Do not throw error/throw better error when providing improper but still valid arguments to
mount
Additional details
We derive information from the component/class passed into
cy.mount
such as the name of the component or whether it is a standalone component (Angular). Our mount would error in certain scenarios:cy.mount(some_primitive_value)
e.g.cy.mount('Hello World')
class MyClass {}; cy.mount(MyClass)
The goal of this PR isn't to validate what is passed. If
cy.mount(null)
is called, stuff should break and that's expected but if the types allow for certain values likecy.mount(5)
then it shouldn't throw an error. If it does throw an error, it should be the render throwing the error and notCannot read "displayName" of undefined
where we are trying to pull info from the component passed in.Steps to test
System-tests help here. If you want to test an external project, you'll first have to build the mount package and then symlink/copy it to your project's
node_modules/cypress/{framework}
How has the user experience changed?
Before:
Screen.Recording.2022-11-07.at.2.17.56.PM.mov
After:
Screen.Recording.2022-11-07.at.2.20.16.PM.mov
PR Tasks
cypress-documentation
?type definitions
?