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

cy.window().its( 'mw' ) is executing the inspect method on the subject #30662

Open
micgro42 opened this issue Nov 21, 2024 · 2 comments
Open

Comments

@micgro42
Copy link

micgro42 commented Nov 21, 2024

Current behavior

The instruction

cy.window().its( 'mw' ).should( 'have.property', 'propertyToCheckFor' );

is executing the mw.inspect method if it exists.

That is fully unexpected and might lead to undefined behavior, including throwing an Exception and thus failing the test.

Desired behavior

The instruction

cy.window().its( 'mw' ).should( 'have.property', 'propertyToCheckFor' );

is not executing any methods of the window.mw object at all.

Test code to reproduce

https://github.com/micgro42/cypress-MFE-inspect

Cypress Version

13.16.0

Node version

v20.15.0

Operating System

Ubuntu 24.04.1

Debug Logs

GitHub complained that the comment is too long when I tried to add the entire debug output here. Please be more specific with what you need here. Alternatively, the debug output should be trivial to reproduce with the test code provided above.

Other

No response

@ryanthemanuel
Copy link
Collaborator

Hi @micgro42. This is actually a function of how chai works in terms of its matchers (in this case the have.property matcher). This can be seen by changing the test code to:

    cy.window().then((win) => {
      expect(win.mw).to.have.property('propertyToCheckFor');
    })

or even:

    cy.window().then((win) => {
      expect(win.mw).to.exist;
    })

If calling inspect is causing a problem, I would recommend switching up how you're asserting. Something like this could work:

    cy.window().then((win) => {
      expect(win.mw.propertyToCheckFor).to.exist;
    })

@micgro42
Copy link
Author

@ryanthemanuel: Thank you for your quick response and suggestions! 🙏
(Though doesn't .then break retry-ability?)

However, I do miss somewhat it acknowledging the core point that this is a bug resulting in unexpected and undocumented behavior in Cypress.

I understand, that from Cypress' point of view, this is also an upstream bug in a library that you're using. But I still think this should remain open until Chai fixes that behavior and you can update it in your dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants