-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
Hi @micgro42. This is actually a function of how 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;
}) |
@ryanthemanuel: Thank you for your quick response and suggestions! 🙏 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. |
Chai, a Cypress dependency has a "feature" that to pretty-print an object it tries to invoke the `inspect` method on that object if it exists, expecting to receive a meaningful string representation. Obviously, this harshly clashes with any other uses a method called "inspect" might have on an object. In our case, the `mw` global js object has an `inspect` method to report module performance or something. However, this method being invoked with the entirely unrelated arguments provided by Chai is leading to a ResourceLoader exception. That is triggered when referencing `mw` in a call to `.its` from `cy.window()`. This change works around that problem by referencing `mw.loader` instead and checking for it having the `using` property, by which point the RL modules should be loaded and we can make API calls. For the upstream cypress/chai bug see: cypress-io/cypress#30662 Change-Id: I4bc0c39c8f50cb96eccf409bdcab4554b84af529
* Update GrowthExperiments from branch 'master' to 68180a0def8e6b125c8a172128de4b10c1f529b0 - Merge "test(cypress): work around Chai "feature"" - test(cypress): work around Chai "feature" Chai, a Cypress dependency has a "feature" that to pretty-print an object it tries to invoke the `inspect` method on that object if it exists, expecting to receive a meaningful string representation. Obviously, this harshly clashes with any other uses a method called "inspect" might have on an object. In our case, the `mw` global js object has an `inspect` method to report module performance or something. However, this method being invoked with the entirely unrelated arguments provided by Chai is leading to a ResourceLoader exception. That is triggered when referencing `mw` in a call to `.its` from `cy.window()`. This change works around that problem by referencing `mw.loader` instead and checking for it having the `using` property, by which point the RL modules should be loaded and we can make API calls. For the upstream cypress/chai bug see: cypress-io/cypress#30662 Change-Id: I4bc0c39c8f50cb96eccf409bdcab4554b84af529
@micgro42 I think this is expected behavior, so it should likely be documented better. |
Current behavior
The instruction
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
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
The text was updated successfully, but these errors were encountered: