Can anyone offer guidance on how to incorporate chainable commands with if/else logic without duplicating code? Specifically, I want to avoid repeating
.trigger('focus', {force: true}).click({force: true});
in both the if and else statements. I have tried using return in the logic but it's not working as expected.
const selectedOption = 'I am option'
cy.get('.my-selector')
.contains(selectedOption)
.scrollIntoView()
.then(($option) => {
if ($option.find('input').length === 1) {
cy.wrap($option.find('input')).trigger('focus', {force: true}).click({force: true});
} else {
cy.wrap($option).trigger('focus', {force: true}).click({force: true});
}
});
utilizing return
.then(($option) => {
if ($option.find('input').length === 1) {
return cy.wrap($option.find('input'));
}