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

cy.focused().type("text") shows cypress/unsafe-to-chain-command error #140

Closed
BCaspari opened this issue Aug 9, 2023 · 13 comments · Fixed by #141
Closed

cy.focused().type("text") shows cypress/unsafe-to-chain-command error #140

BCaspari opened this issue Aug 9, 2023 · 13 comments · Fixed by #141

Comments

@BCaspari
Copy link

BCaspari commented Aug 9, 2023

After an update to 2.14.0, the cypress/unsafe-to-chain-command rule is triggered by code as
cy.focused().type("text").
This should be no problem however, as the cypress docu states cy.focused() is a query, and it is safe to chain further commands (https://docs.cypress.io/api/commands/focused)

@nagash77
Copy link
Contributor

nagash77 commented Aug 9, 2023

Hi @BCaspari , you are correct that cy.focused is a query and safe to chain off of. cy.focus is however not safe to chain off of. I believe this might be an overzealous match from this PR. Thank you for reporting this issue. I am not sure when we will be able to address this issue, so for the time being I would suggest downgrading and pinning your version to avoid this problem.

@nagash77 nagash77 added triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. E2E labels Aug 9, 2023
@MikeMcC399
Copy link
Collaborator

This would also impact cypress-io/cypress-example-kitchensink if it weren't for the fact that unsafe-to-chain linting is currently disabled in that repo.

@lgenzelis
Copy link

lgenzelis commented Aug 14, 2023

Even doing cy.focused().blur(), which is an example given in the docs, raises this error now.

@MikeMcC399
Copy link
Collaborator

@nagash77

Since v2.14.0 has introduced an unplanned breaking change, if this issue can't be fixed in a timely way, then it should be considered to revert the PR #137 and release a corrected version without the breaking change.

@code-jorge
Copy link

I believe this to be an unintended side effect from this change specifically:

49c6eb3#diff-43276831483080b5e9f5d83eb749bebf8e0d7167aa50c64cbc4fc1bcd7e0698bR121

Which comes from here:

49c6eb3#diff-43276831483080b5e9f5d83eb749bebf8e0d7167aa50c64cbc4fc1bcd7e0698bR111-R115

Seems like before this change, any selector had to exactly match the name of the "unsafe to chain" selectors. Now, because of the regex, if the selector's name partially matches one of the names, the linter will complain.

e.g. /focus/.test("focused") returns true, so the linter complains.

@ext
Copy link

ext commented Sep 13, 2023

Any progress on this one? Is there anything I could do to help? The issue and the cause seems to be identified.

@dominicfraser
Copy link
Contributor

I've made a PR to illustrate the false positive, and a potential fix, here: #142

@MikeMcC399
Copy link
Collaborator

@dominicfraser

@dominicfraser
Copy link
Contributor

I believe so yes ☺️

A more scalable solution is proposed in #141 (rather than the fast hotfix I did) - but for this specific bug the merged PR and new release solves it adequately 👍

@dominicfraser
Copy link
Contributor

@imaliouris
Copy link

the implementation is wrong.. Not only focused but every command that contains any of the unsafe to chain commands shows cypress/unsafe-to-chain-command error.
i.e. custom command submitBtn shows cypress/unsafe-to-chain-command error.

Please check #141 because we have to rename our functions or disable linting and that's not the proper solution..

@MikeMcC399 MikeMcC399 added the bug label Apr 17, 2024
@MikeMcC399
Copy link
Collaborator

@cypress-app-bot
Copy link

🎉 This issue has been resolved in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@MikeMcC399 MikeMcC399 removed triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. E2E labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants