I have recently started working with TypeScript and I am trying to extract a list of values from an ag-grid column in order to compare them with a string array. Below is the function I created for this purpose. However, it appears that my ActualRatingsValues.push(text); line is not populating the ActualRatingsValues array as expected. I am unsure if this issue has something to do with promises. Can someone explain how promises work?
validateRatingsValues() {
const ExpectedRatingsValues: Array<string> = ['A', 'B', 'C', 'D', 'E'];
const ActualRatingsValues: Array<string> = [];
const wrapper = element.all(by.css('.ag-pinned-left-cols-container div[col-id="name"]'))
.getText()
.then(text => {
ActualRatingsValues.push(text);
});
let match = true;
if (ExpectedRatingsValues != null && ActualRatingsValues != null) {
if (ExpectedRatingsValues.length !== ActualRatingsValues.length) {
match = false;
} else {
for (let i = 0; i < ActualRatingsValues.length; i++) {
if (ActualRatingsValues[i].toString !==
ExpectedRatingsValues[i].toString) {
match = false;
break;
}
}
}
} else {
match = false;
}
expect(match).toBeTruthy();
}