Skip to content

Cypress.Commands.overwrite doesn't pass down the context #5101

Closed
@x-yuri

Description

@x-yuri

Current behavior:

Cypress.Commands.overwrite('then', function(originalCommand, subject, fn, options = {}) {
    return originalCommand.call(this, subject, options, fn);
});
 
specify('aliases work', function () {
    cy.wrap(1).as('myAlias');
    cy.wrap(2).then(function(subj) {
        expect(this.myAlias).to.eq(1); // undefined
    });
});

Desired behavior:

The test succeeds.

Steps to reproduce: (app code and test code)

https://github.com/x-yuri/issues/tree/cypress-overwrite

More info

Cypress.Commands.overwrite() is used by cypress-commands package. Is there a possibly better way to change then() command?

Versions

Cypress 3.4.0, Arch Linux, Electron 61

Metadata

Metadata

Assignees

No one assigned

    Labels

    pkg/driverThis is due to an issue in the packages/driver directorytype: unexpected behaviorUser expected result, but got another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions