Create long text using Cypress._.repeat
Advent day 15: How to quickly create long strings for testing
Imagine you want to check how the application handles long strings. You can quickly get a nice string using the Lodash _.repeat function, already bundled with Cypress.
// need to generate text longer than 100 characters
const text = Cypress._.repeat('123456789 ', 11)
expect(text).to.have.length(110)
cy.get('#text').type(text).blur()
Great, now the test can confirm the app truncates the output
cy.get('#output')
.invoke('text')
.should('have.length', 33)
.and('match', /\.\.\.$/)
Beautiful test and here is the Command Log
You can find this recipe and many more at my Cypress examples site