No código abaixo, por que tenho que repetir cy.wrap(article)
em vez de encapsulá-lo uma vez e armazenar o resultado encapsulado em uma variável reutilizável, como mostrado na linha três?
verifyArticleContent(article: JQuery<HTMLElement>, expected_article: Topic) {
// Wrapping once does not work.
// const article2 = cy.wrap(article)
// Title
cy.wrap(article).find('h2 a')
.should('have.text', expected_article.title)
.and('have.attr', 'href', '/forum/discussion/' + expected_article.id)
// Description
cy.wrap(article).find('p.data-description').should('have.text',
expected_article.description.substring(0, 300) + ' ...')
// Details
cy.wrap(article).find('p.data-author-date').should('have.text',
expected_article.user?.username + ', ' + // username
Util.dateToString(expected_article.date, 'en')) // date
}
Mais esclarecimentos e um exemplo de como pensei que funcionaria:
verifyArticleContent(article: JQuery<HTMLElement>, expected_article: Topic) {
// Wrapping once does not work.
const article2 = cy.wrap(article)
// Title
article2.find('h2 a')
.should('have.text', expected_article.title)
.and('have.attr', 'href', '/forum/discussion/' + expected_article.id)
// STOPS WORKING HERE. If I comment out this description check, it fails on the details with the same (almost) error.
// Description
article2.find('p.data-description').should('have.text',
expected_article.description.substring(0, 300) + ' ...')
// Details
article2.find('p.data-author-date').should('have.text',
expected_article.user?.username + ', ' + // username
Util.dateToString(expected_article.date, 'en')) // date
}