bahmutov / cypress-map

Cypress query commands for v12+
https://glebbahmutov.com/blog/cypress-v12/
MIT License
48 stars 2 forks source link

cy.sample changes static alias value #200

Open KrzGruszcz opened 4 months ago

KrzGruszcz commented 4 months ago

To reproduce:

it("fails", () => {
  cy.visit("https://example.cypress.io");

  cy.get(".home-list ul > li")
    .sample()
    .invoke("text")
    .as("commandName", { type: "static" })
    .then(cy.log);

  cy.get("@commandName").then(cy.log);
});

The yielded commandName value should not change (since it's a static value), but it's changing (parentsUntil vs platform in this example):

image
bahmutov commented 4 months ago

Ughh, Cypress keeps calling the sample command for some reason, instead of using the previously returned subject :(

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/aliasing.ts

Screenshot 2024-06-28 at 7 57 30 AM

Really weird behavior, need to investigate how to it works under the hood.

KrzGruszcz commented 1 month ago

any update here Gleb @bahmutov ?

bahmutov commented 1 month ago

No updates @KrzGruszcz I did not have time to look into this