Currently, I am in the process of testing an application that showcases graphs using rickshaw and d3. The tests are being run with protractor and jasmine. It's worth noting that this question is not specific to this particular scenario but rather more general in nature.
The test involves hovering the mouse over a graph and capturing the text displayed for each point (example here). This text array is then compared against a predefined array.
This pseudo code snippet should help illustrate the issue:
var graph = ... //
var promises = [];
var promise = graphElement.getSize().then(function(size){
_.times(size, function(i) {
moveMouse(i, 0);
promises.push(graph.element(by.css('.hover-text')).getText());
});
return promises;
});
promise.magicallyWaitForAllOfThem();
_.each(promises, function(textPromise){
expect(textPromise).toBe('something');
});
The problem arises because I need the size to be resolved first, leaving me without a method to wait for all promises to resolve and return an array of text promises that can later be used with expect().
EDIT: I have explicitly mentioned protractor/jasmine.