selene icon indicating copy to clipboard operation
selene copied to clipboard

should we keep be._empty as 4-in-1 condition and correspondingly remove its experimental _ prefix?

Open yashaka opened this issue 1 year ago • 2 comments

be._empty is similar to be.blank... But be.blank works only for singular elements: if they are a value-based elements (like inputs and textarea) then it checks for empty value, if they are text-based elements then it checks for empty text content.

The be._empty condition works same but if applied to collection then will assert that it has size 0. Additionally, when applied to "form" element, then it will check for all form "value-like" inputs to be empty.

Hence, the blank condition is more precise, while empty is more general. Because of its generality, the empty condition can be easier to remember, but can lead to some kind of confusion when applied to both element and collection in same test. Also, its behavior can be less predictable from the user perspective when applied to form with textarea, that is both "value-like" and "text-based" element. That's why it is still marked as experimental.

yashaka avatar Jul 07 '24 15:07 yashaka

I briefly reviewed the test cases, and I agree that the current polymorphic behavior could create confusion

Instead of be._empty, we could make the API more explicit (although I know this approach my be more verbose, in this specific case I think that clarity > brevity):

For collections: ss('.items').should(have.size(0))

For form/input values: s('input').should(be.blank) s('form').should(have.all_inputs_blank) --> a bit clearer I think?

For text content: s('div').should(be.blank)

I do think this could make the code more predictable and self-documenting. I do hope I'm not missing any context though and my proposal makes sense.

@yashaka

cachebag avatar Jan 27 '25 05:01 cachebag

@cachebag Seems like you are right... We can keep be._empty still marked as experimental with _ prefix, just in case somebody else will find other arguments...

In meantime it seems like a good idea to add have.all_inputs_blank condition...

yashaka avatar Jan 27 '25 15:01 yashaka