I am trying to pass multiple condition in single if but code is ignoring it.
cy.get("locator").each($el) => {
if($el.hasClass("flatpiker-day ") && $el.text() == day)
{
//some code
return false;
}
}
I am trying to pass multiple condition in single if but code is ignoring it.
cy.get("locator").each($el) => {
if($el.hasClass("flatpiker-day ") && $el.text() == day)
{
//some code
return false;
}
}
2
Answers
The condition
$el.hasClass('flatpiker-day')
could be.find('.'flatpiker-day')
and the condition$el.text() == day
could be.contains(day)
, so a good test would beBut please note, if you are testing a calendar, the display can sometimes show the
day
twice.You would have to give detail of the DOM to resolve that.
If this is the HTML of the calendar
then you can avoid double-up of
day === 30
by using thearia-label
, which has the full date in it’s value.In general, aria attributes often provide a good way to select an element – see testing-library for a full discussion.