Protractor map function returning undefined
This confused me so I thought I'd add an answer to help others...
While I understood that map()
returns a promise, because I was using it in an expect
, I thought it would be resolved, and then should act like an array. Nope. It returns an object, that looks like an array, but is not an array.
I ran into this problem, and none of these solved this for me. For anyone googling like I was here is the real answer:
element.all(by.css('ul.widget-grid')).map(function(widget, index) { return { index: index, title: widget.element(by.css('div.title')).getText() }}).then(function(map){ this.widgets = map; });
map()
returns a promise that would resolve into an array of objects.
I think you meant to check the first widget's index and title:
var widget = page.widgets[0];expect(widget.index).toBe(0);expect(widget.title).toBe('The Title');