bahmutov / cypress-map

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

cy.sample changes static alias value #200

Open KrzGruszcz opened 2 weeks ago

KrzGruszcz commented 2 weeks 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 2 weeks 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.