Skip to content

Throw when a value other than cy is returned from a test or command function #463

@brian-mann

Description

@brian-mann

During an e2e or integration test, we should throw a specific error message when:

  1. a value is returned to a callback function
  2. in either a mocha it test or in a custom command
  3. and a cy command was invoked.

We're going to opt for a stricter API up front contract instead of being magical behind the scenes and forcing return values unbeknownst to the developer.

The following situations should throw:

Cypress.Commands.addParent("foo", function(){
  cy.get("body").should("have.class", "foo")

  return "foobarbaz"
})

it("should throw", function(){
  cy.get("body").should("have.class", "foo")
   
  // currently Cypress detects this and forcibly
  // returns 'cy'. Instead we should throw.
  return "foobarbaz"
})

it("should also throw", function(){
  cy.foo()
})

it("does not throw", function(){
  // this is okay since no cy commands were invoked!
  expect(true).to.be.true
})

Metadata

Metadata

Assignees

Labels

type: enhancementRequested enhancement of existing feature

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions