'How to check if an element contains multiple items in Cypress.io

How can I check if an element contains multiple items in Cypress.io without replicating my code so much?

Current Example:

cy.get(".column")
  .children()
  .contains("Name");

cy.get(".column")
  .children()
  .contains("Age");

cy.get(".column")
  .children()
  .contains("Weight");

cy.get(".column")
  .children()
  .contains("Height");

cy.get(".column")
  .children()
  .contains("Favorite Color");


Solution 1:[1]

You can do it in this way:

cy.get('.column')
  .children()
  .should('contain', 'Name')
  .and('contain', 'Age')
  .and('contain', 'Weight')
  .and('contain', 'Height')
  .and('contain', 'Favorite Color')

Solution 2:[2]

Sometimes you can do it in this way:

     const column = ['Name', 'Age', 'Weight', 'Height']

        column.forEach(function (value) {
            cy.get('.column')
              .children()
              .should('contain', value)
        })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yevhen Laichenkov
Solution 2 Darya