Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwriting "type" command is breaking #28118

Open
tnrich opened this issue Oct 23, 2023 · 2 comments
Open

Overwriting "type" command is breaking #28118

tnrich opened this issue Oct 23, 2023 · 2 comments
Labels
prevent-stale mark an issue so it is ignored by stale[bot] type: bug v12.0.0 🐛

Comments

@tnrich
Copy link
Contributor

tnrich commented Oct 23, 2023

Current behavior

Hi there @bahmutov and others!

I'm trying to overwrite the "type" command to make it more robust for our app. The override I'm using seems to work fine on a previous version of Cypress (v8) but now appears to be failing on the most recent version of cypress.

Here is the minimal amount of overwriting code necessary to reproduce the error (note I'm not actually doing any thing besides adding a wait(0) in front of the "type" command:

Cypress.Commands.overwrite(
  "type",
  (originalFn, element, text, options = {}) => {
    // this code works:
    // return originalFn(element, text, options);
    
    // // this code does not work:
    cy.wait(0).then(() => {
      // run the original type command on the same element
      return originalFn(element, text, options);
    });
  }
);

Running the following test

describe("page", () => {
  it("works", () => {
    cy.visit("https://example.cypress.io/commands/actions");
    cy.window().then((win) => {
      console.log(`win:`, win);
    });
    cy.get(".action-email")
      .type("[email protected]")
      .should("have.value", "[email protected]");
  });
});

Produces this output:

image

When I hit print to console I see this:

image

Which brings me to this line of code:
image

Where it appears $el.length === 0 is failing since el does not exist.

Desired behavior

I would like for my type override to work even after a .then() clause.

Test code to reproduce

https://github.com/tnrich/type-overwrite-bug

Cypress package version: 13.3.2
Cypress binary version: 13.3.2
Electron version: 25.8.4
Bundled Node version: 18.15.0

Cypress Version

13.3.2

Node version

18.15.0

Operating System

macOS 12.6

Debug Logs

No response

Other

No response

@jennifer-shehane
Copy link
Member

This error began occuring in 12.0 of Cypress and is likely around changes with our commands related to chaining.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Apr 22, 2024
@jennifer-shehane jennifer-shehane added prevent-stale mark an issue so it is ignored by stale[bot] and removed stale no activity on this issue for a long period labels Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prevent-stale mark an issue so it is ignored by stale[bot] type: bug v12.0.0 🐛
Projects
None yet
Development

No branches or pull requests

3 participants