cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

Document behavior around support file instances

Open elkemper opened this issue 3 years ago • 1 comments

Current behavior

When i'm comparing (===) or expect().to.equal instances of Singleton class, or just any static member of any class, that are returned from method invoked via Cy.Command (or Cy.Task . well, in this case this is expected, thou would be great if could be fixed too) with local link on that object\member - getting result, that are not equal.

Desired behavior

In this situation, Cypress should make this objects\members completely equal. not deep.equal

Test code to reproduce

Repository with test example npm test and npm run open are set up to check

Cypress Version

10.6.0

Node version

v12.22.10/v16.7.0

Operating System

MacOS 11.4 / Windows 10

Debug Logs

No response

Other

No response

elkemper avatar Oct 04 '22 10:10 elkemper

@elkemper thanks for creating an issue. For cy.task, this is expected behavior and won't change. For the commands, the reason why this happens is because the support file is in a separate bundle from the test code, so the singleton instances aren't the same.

This behavior is unlikely to change, but I'm going to route this to our team to update the documentation to point this out explicitly so that our users know what to expect when using support files.

astone123 avatar Oct 06 '22 00:10 astone123

Thank you @astone123 for the reply and explanation. But I have to disagree that is not a reason for the investigation and fixing - this is not only about documentation (we are talking about the cy.command of course). Cy.Command is advertised as clear and pretty way to incapsulate any logic of the testing framework. And it is opposing the traditional page-object pattern, saying - that there is no sense to use it. Now, i seems like that instead you should not use cy.command, and it's better to do everything in your own code and completely ignore cy.command functionality, because it doesn't give any benefit in comparison with any utility class, but it will work in completely unpredictable fashion.

elkemper avatar Oct 07 '22 10:10 elkemper