To do this I’m using wrap() to return a Chainable containing the value I want to return.
Module
function foo() {
return cy.wrap('foo');
}
Cypress.Commands.add('foo', foo);
Test File
cy.foo().then(value => console.log(value)); // foo
Since wrap() is returning a Cypress.Chainable, we can call .then() on our commands. What ever is passed into wrap() is yielded to the next command.
See also: Cypress wrap() documentation