3

So I have an element identified

var errorAlert = element.all('[id*="type-alert"]');

I am trying to create a function that will verify there are 2 alerts displayed..

this.isAlertsDisplayed = function() {
    return expect(errorAlert.count()).toEqual(2);
};

I keep gettin a friken typeError : .toEqual is not a function when I have seen this example work for others.. What am I doing wrong?

Tree55Topz
  • 1,102
  • 4
  • 20
  • 51

2 Answers2

2

your locator is wrong. Your locator should have by.css() or by.id or something like this.

Try var errorAlert = $$('[id="type-alert"]') or var errorAlert = element.all(by.id('type-alert'))

radio_head
  • 1,306
  • 4
  • 13
  • 28
2

@Danny is on the right track. Except that you are simply missing the by.css() part, replace:

var errorAlert = element.all('[id*="type-alert"]');

with:

var errorAlert = element.all(by.css('[id*="type-alert"]'));

Or with:

var errorAlert = $$('[id*="type-alert"]');

Note that you can spot this kind of problems much earlier in the process - statically even before executing your tests and trying to figure out what went wrong. If you would use ESLint and eslint-plugin-protractor plugin (>=1.29.0), the valid-locator-type rule would warn you if you have passed a literal to element() or element.all(), or if you have passed a "by" locator to $() or $$().

And, if you have ESLint configured in your IDE of choice, here is how you would get the warning during the live-coding (example from PyCharm):

enter image description here

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • tried with $$ as well but same result. I ended up just altering the method to look for the last one, that way if there was 0 it would still fail. – Tree55Topz Nov 10 '16 at 20:06
  • @Tree55Topz your problem inspired me to get back to the `valid-locator-type` ESLint rule I was planning to finish. Now it's ready and published. Please see the updated answer. – alecxe Nov 13 '16 at 02:27