We started using primeNG tables and I want to create a function where i access a table to see if certain text elements are present. But i get an error Cannot read properties of undefined (reading 'rows') when i run this.
Please know that the switch statement is work in progress. The error occurs on table.rows(). Anybody an idea to solve this error?
The code is as follows:
verifyTemplatePresent(template: string, table:any) {
cy.get(this.#templateDataTable, {timeout: 30000}).within(() => {
table.rows((element:any) => {
const cellText = element.find('td').eq(0).text();
switch (cellText === template) {
case true:
return cy.get(this.fieldTd(element))
.should('exist');
case false:
return cy.get(this.fieldTd(element))
.should('not.exist');
default:
throw new Error("A wrong text was entered in the table, please change it to a correct value");
}
});
})
}
The table
variable is in the wrong place, move it down one line.
But table.rows()
also looks wrong to me. Should it be table.find('tbody tr')
.
verifyTemplatePresent(template: string) {
cy.get(this.#templateDataTable, {timeout: 30000}).within((table: any) => {
cy.wrap(table).find('tbody tr').each((element:any) => {