Working on an E2E using Ramda. I'm not getting how to convert a simple IF condition using Ramda Cond.
Code using If :
if (constraint == 'required') {
// then only do something
await waitForElementToBeClickable(constraintElement);
await constraint.click();
}
I don't want the else because I want the action to happen only if the constraint is present.
I've done this so far using constraint but it's not working :
await waitForElementToBeClickable(cond([
[equals('required'), always(constraintElement)],
])(constraint), this.browser);
const constraintCheck = cond([
[equals('required'), () => constraintElement.click()],
]);
await constraintCheck(constraint);
In some cases, I do not want to pass the constraint. Then the Condition should not execute at all. But it is always getting executed and throwing the error : Cannot read property 'isPresent' of Undefined.
By looking at your example, it seems that you use
constraintboth as a string and an object which may cause unnecessary confusion. I know you can implement atoString()method on an object but I'm not sure if that always plays nicely when you integrate with external librariesI would suggest that you convert your object into a string before you make the check:
Then if you don't need an "else" branch, you could consider using when.