troccoli's avatar

Create multiple models in Cypress

In one of my tests I need to create two models before visiting a page.

Therefore I have something along the following (Im using the laracast/cypress package)

cy.create({
  model: 'App\\Models\\Firm',
}).then((firm) => {
  cy.create({
    model: 'App\\Models\\DataPortal',
    state: {
      boughtBy: firm.id,
    },
  }).then((dataPortal) => {
    cy.login({
      attributes: { name: 'Test User' },
      state: { firm: firm.id },
    })
    cy.visit(Cypress.Laravel.route('data-portal.explore-all'))
    ...

Because I have to chain the creation of the models, the test is not very readable. I'm sure I am not the only one facing this issue, but how is everybody else solving it? Is it solvable, or is it something I will have to live with?

0 likes
0 replies

Please or to participate in this conversation.