angulartestingcypresse2e-testinge2e

Cypress represent the OR in a loop


I am trying to test the input values of a table, but I cannot represent the OR, nor can I skip a cell of a table. the table is cycled, it has all positive values, except in a cell where in automatic it is negative so either I have to skip that cell, or I have to check all the cells if it is negative or positive...

  cy.get('my-table > .my-table tbody > tr > td:not(:nth-child(5)) > input:not([disabled])')
  .each(el => {
    cy.wrap(el).should('have.value', '0.1234' || 'have.value', '-0.1234');
  });

Already entering the td: not(:nth-child(5)) should skip a cell (the one with the negative value) while it doesn't... so I tried with a || condition to test if it's positive or negative but it still doesn't work...


Solution

  • If you are checking the value to be one of either 0.1234 or -0.1234, you can use this:

    cy.get('my-table > .my-table tbody > tr > td:not(:nth-child(5)) > input:not([disabled])').each(($ele) => {
      expect($ele.val().trim()).to.be.oneOf(['0.1234', '-0.1234'])
    })