Skip to content

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

@marcelhohn

Description

@marcelhohn

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions