Skip to content
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

Merged
merged 3 commits into from Nov 7, 2022
Merged

Conversation

ZachJW34
Copy link
Contributor

@ZachJW34 ZachJW34 commented Nov 7, 2022

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:

  • React: calling cy.mount(some_primitive_value) e.g. cy.mount('Hello World')
  • Angular: calling mount with an undecorated component e.g. 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 like cy.mount(5) then it shouldn't throw an error. If it does throw an error, it should be the render throwing the error and not Cannot 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

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 7, 2022

Thanks for taking the time to open a PR!

Copy link
Contributor

@lmiller1990 lmiller1990 left a 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

npm/angular/src/mount.ts Show resolved Hide resolved
@@ -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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@rockindahizzy rockindahizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@lmiller1990
Copy link
Contributor

Looks good!

@cypress
Copy link

cypress bot commented Nov 7, 2022



Test summary

4249 0 1098 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 7a390d3
Started Nov 7, 2022 10:18 PM
Ended Nov 7, 2022 10:36 PM
Duration 18:31 💡
OS Linux Debian -
Browser Multiple

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

@ZachJW34 ZachJW34 merged commit 838dd4f into develop Nov 7, 2022
@ZachJW34 ZachJW34 deleted the zachw/safer-mount branch November 7, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gracefully handle failures when deriving component name during mount
3 participants