I am trying to debug a test in a CucumberJS/Protractor/Chai-as-promised stack.
var tableDataRows = $('.example-table-under-test').$$('tr');
var dataToTest = tableDataRows.map(function(rows, index) {
if (index > 0) {
var cells = rows.$$('td');
return {
'ATTRIBUTE A': cells.first().getText(),
'ATTRIBUTE B': cells.get(1).getText(),
'ATTRIBUTE C': cells.get(2).getText(),
'ATTRIBUTE D': cells.get(3).getText(),
'ATTRIBUTE E': cells.get(4).getText(),
'ATTRIBUTE F': cells.get(5).getText()
};
}
});
return chai.expect(dataToTest).to.eventually.deeply.equal(tableSpec.hashes());
When I ran the test, I got the following error message despite the cucumber specs matching up with the table values on the screen:
AssertionError: expected [ Array(8) ] to deeply equal [ Array(7) ]
I figured since the mapper was ignoring the first row of th
elements, 7 should equal 7, so I wanted to debug the test. At first I tried just adding then
to the map
like tableDataRows.map(...).then(console.error)
(since .map
off a protractor element.all
/ $$ returns a promise) to output the data mapped from the tableDataRows
, but that didn't result in any data.
I tried then
ing a random function that didn't even use the resolved output to just see if it was executing, and that it didn't - so I figure that just a then
isn't resolving the promise.
.then(function() {
console.error("I executed");
// this didn't work either
});
After that, I tried putting a log line in the map function just above the return since that seemed to be resolving, and that worked - 7 times (which is what I'd expect for the mapper skipping the header row, but it's confusing because the test claims there's 8 elements in the array. Anyway..)
So somehow the .to.eventually
in chai-as-promised
is resolving promises (like the documentation said it would), but I don't see how my .then()
after the .map()
function isn't resolving anything, or how any of my other attempts weren't resolving the promise either.
Is it possible to resolve the promise without returning the chai.expect
(presumed) promise that wraps the promise used to get data for the expect? -- I also noticed nothing would resolve if I just had chai.expect(...).to.eventually.equal(...)
without a preceding return.