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

Assignment of return value in ternary operator is not recognized #150

Open
marcelhohn opened this issue Feb 27, 2024 · 1 comment
Open

Comments

@marcelhohn
Copy link

When assigning the return value of a Cypress command to a variable via a ternary operator, the plugin does not throw an error:

Cypress.Commands.add(
  'getFormByName',
  { prevSubject: 'optional' },
  (subject) => {
    const formGroupSelector = 'form-group';
    // This throws an error, as expected
    let formGroup1 = cy.get(formGroupSelector);

    // This does not throw an error, although I would expect it to do so
    const formGroup = subject
      ? cy.wrap(subject).find(formGroupSelector)
      : cy.get(formGroupSelector);

    formGroup.find('other-selector');
    // do more stuff
  }
);

Is this the expected behavior? If not, it would be great if the compiler could also throw an error when assigning a value via the ternary operator.

You can also try it out on this stackblitz: https://stackblitz.com/edit/eslint-cypress-4eyvq9i?file=cypress.js

@jennifer-shehane
Copy link
Member

@marcelhohn We'd be open to a PR for this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants