Replace cy.then command

Many people have a problem with the cy.thenopen in new window command. It behaves almost like a promise, causing confusion. Let's replace it with a custom cy.later command.

// if anyone tries to use cy.then in the spec code or in a plugin
// we will get an error
  function (then, subject, cb, allowUse) {
    if (!allowUse) {
      throw new Error('Using cy.then command is disallowed')
    return then(subject, cb)

  { prevSubject: true },
  (subject, cb) => {
    // cy.later behaves just like cy.then
    // which we implement by calling the original cy.then command
    return'then', subject, cb, true)

  .should('be.a', 'string')
  .later((x) => x + x)
  .should('equal', 'HelloHello')

Read the blog post Replace The cy.then Commandopen in new window.