featurist / browser-monkey

Reliable DOM testing
https://browsermonkey.org
53 stars 6 forks source link

Multiple matches in shouldHave({ text: ... }) #23

Open joshski opened 8 years ago

joshski commented 8 years ago

It wasn't clear to me what this means exactly:

component.shouldHave({ text: ['a', 'b'] });

Based on failure messages, I figured it means: the component should match 2 elements, and the text of each element should match the corresponding index in the array. My problem with this behaviour, is that it leads towards more specific assertions than I would like to make. When I want to say "my page should show these messages, but I don't care where", I try this:

myPage.shouldHave({ text: ['must have numbers', 'must not have punctuation'] });

...but that's not quite right, because myPage only matches one element. So I end up doing this:

myPage.find('.errors li').shouldHave({ text: ['must have numbers', 'must not have punctuation'] });

...but now my assertions are more coupled to the structure of the page than I would like. Currently that means I do:

Promise.all(errors.map(function(error) {
   return myPage.shouldHave({ text: error });
})

Is there a neater way to do this?

It strikes me that an alternative shouldHave({ text: [] }); could do this instead:

1. Get the concatenated text of all elements matched by the component.
2. Check if each string in the array is a substring.
dereke commented 7 years ago

@refractalize what are your thoughts on this?