question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alias seems to not store it's value

See original GitHub issue

Current behavior

During the test I’m comparing two values

First one is stored as ‘backgroundImageDefault’ with following code

    cy.get(selectors.pageAddress)
      .prev()
      .invoke('css', 'backgroundImage')
      .as('backgroundImageDefault');

At this point the backgroundImageDefault has value https://host.com/smth/defaultImage.jpg.

Then I’m changing the image, the new image obviously has a new address, https://host.com/smth/changedImage.jpg.

    cy.get('@backgroundImageDefault').then((background) => {
      cy.get(selectors.pageAddress)
        .prev()
        .should('not.have.css', 'background-image', background);
    });

It fails becouse when comparing it seems that alias ‘backgroundImageDefault’ now has value of https://host.com/smth/changedImage.jpg instead of it’s assigned value of https://host.com/smth/defaultImage.jpg.

Desired behavior

Until I upgraded to 12.0.0/12.1.0 the test simply passed and the value stored in the backgroundImageDefault was correct.

Test code to reproduce

It’s the code mentioned in current behaviour

Cypress Version

12.1.0

Node version

v16.15.1

Operating System

macOS 13.1

Debug Logs

No response

Other

No response

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:5
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ArturMiszkowiczcommented, Dec 21, 2022

I like A and B 😃

B is more explicit but A gives no work if someone is not using aliases to store values

1reaction
samtsaicommented, Dec 20, 2022

I like A, would we probably default to { type: 'query' } and document that this is how it was always meant to work? I mean it’s a little more work for people depending on the value but speaking for my team, we can manage to be explicit in our tests that need a different default.

I think C would be confusing to change it on the get at least in my mind we focus more on when we store values, like if we wanted to do a .as("originalValue") and then later compare to a new value, sample usage:

cy.get("@originalUrl").then(url => {
    cy.url().as("newUrl").should("not.equal", url)
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript function aliasing doesn't seem to work
This function is declared in the Window scope and when you invoke it the value of this inside the sum function will be...
Read more >
Variables and Aliases
Whenever you have mutable objects and you're trying to compare them, you'll need to store their values. Using const is a perfect way...
Read more >
Using Alias Sets Part 1
Alias sets provide a means resolving attribute values that specify ACL, ... Alias sets are stored as dm_alias_set objects in Documentum.
Read more >
Lambda function aliases
An alias can point only to a function version, not to another alias. You can update an alias to point to a new...
Read more >
Alias Variables Extensions
An object can be mapped onto, and stored and manipulated in an array, ... SET with an alias container as left-hand side target...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found