cypress-io / eslint-plugin-cypress

An ESLint plugin for projects that use Cypress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assignment of return value in ternary operator is not recognized

marcelhohn opened this issue · comments

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

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