cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.85k stars 3.17k forks source link

Cypress consumes `expect()` function as a property of global `cy` and not as a module. #17564

Closed cowboyd closed 1 year ago

cowboyd commented 3 years ago

Current behavior

@bigtest/cypress registers an expect command in order to make interactor-based assertions. This works well, except when you try to mix interactor assertions with vanilla cypress assertions using the should() syntax, in which case, they break.

cy.expect is not part of the public API, nor is it part of the TypeScript typings and in all of the documentation, the recommendation is to use the global expect() function for BDD style assertions, but when an expect command is added, it causes should() style assertions to break because internally cypress is neither consuming it as a global, nor an es module, but as a property on the global cy object.

https://github.com/cypress-io/cypress/blob/61aa287c459d5aeb88405818c1c6519988e20275/packages/driver/src/cy/commands/asserting.js#L31

Desired behavior

In this situation, Cypress should consume this function as a normal JavaScript module so that there is no hidden conflict with the command namespace. The style of consuming a module as a property of a global object was common before the era of modern bundling and especially the predominance of ES modules, but they give rise to hidden gotchas like this one.

Test code to reproduce

https://github.com/cowboyd/cypress-test-tiny/tree/expect-command

Cypress Version

=6

Other

No response

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 1 year ago

This issue has been closed due to inactivity.