ember-cli-page-object icon indicating copy to clipboard operation
ember-cli-page-object copied to clipboard

Document the difference between queries and predicates

Open benshine opened this issue 9 years ago • 3 comments

The doc has sections for queries and predicates, but it's not clear to me exactly what the difference is. It seems important though. Something about how they are called, maybe?

Some documentation would help here -- or does it already exist and I'm missing it?

benshine avatar Jul 06 '16 00:07 benshine

I think I understand this now, and I can clarify my confusion, at least: predicates return a function that must be called. queries simply return data. If we want to know whether text inside an element with selector AwesomeLabel matches some string, we can ask for that in two ways.

  1. Query the text and then check whether it matches ourselves: labelText: text('.AwesomeLabel'),
  2. with a contains function: labelContains: contains('.AwesomeLabel')

The big difference here is how we'd use those two functions.

console.log(el.labelText); // Just a get
console.log("text matches 'Alison'?", el.labelContains("Alison"));

benshine avatar Jul 06 '16 02:07 benshine

@benshine that's correct, contains generates a function you can use to test elements for content. We need to improve the documentations a lot here to make it easy to understand how it works.

san650 avatar Jul 06 '16 15:07 san650

Also note that predicates always return true / false values as opposed to queries which return values from the DOM element (text content, attribute values, etc.).

san650 avatar Jul 06 '16 15:07 san650