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

fix: Allow 'this' to be used in overridden commands #18899

Merged
merged 2 commits into from Nov 22, 2021

Conversation

BlueWinds
Copy link
Contributor

User facing changelog

Cypress commands that rely on this can now be overridden cleanly,

Additional details

Previously, there was no clean way to invoke an overridden command that, for example, read the test title:

Cypress.Commands.add('foo', function () {
  cy.log(this.test.title) // this works if not overwritten
})

Cypress.Commands.overwrite('foo', function (originalFn) {
  return originalFn.call(this) // throws error, because the originalFn is not *actually* the original function, but a wrapper around it.
})

I don't believe this requires any change in the documentation - it's a fairly niche limitation for command authors. This just makes our API work as you would expect if familiar with JS, instead of having an unexpected limitation. There was no particularly good reason for this limitation, and removing it is easy.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue or this PR been tagged with a release in ZenHub?

@BlueWinds BlueWinds requested a review from a team as a code owner November 12, 2021 20:44
@BlueWinds BlueWinds self-assigned this Nov 12, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 12, 2021

Thanks for taking the time to open a PR!

@BlueWinds BlueWinds changed the title Allow 'this' to be used in overridden commands fix: Allow 'this' to be used in overridden commands Nov 12, 2021
@cypress
Copy link

cypress bot commented Nov 12, 2021



Test summary

18704 1 202 0Flakiness 2


Run details

Project cypress
Status Failed
Commit 42e55ec
Started Nov 22, 2021 8:16 PM
Ended Nov 22, 2021 8:27 PM
Duration 11:49 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


Failures

cypress/integration/cypress/proxy-logging-spec.ts Failed
1 Proxy Logging > request logging > xhr log has response body/status code

Flakiness

commands/net_stubbing_spec.ts Flakiness
1 network stubbing > waiting and aliasing > can timeout waiting on a single request using "alias.request"
cypress/proxy-logging-spec.ts Flakiness
1 Proxy Logging > request logging > xhr log has response body/status code

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@tgriesser tgriesser self-requested a review November 16, 2021 20:00
@BlueWinds BlueWinds merged commit 5dc6c88 into develop Nov 22, 2021
@BlueWinds BlueWinds deleted the issue-18892-overriden-commands-pass-through-this branch November 22, 2021 20:33
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 23, 2021

Released in 9.1.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.1.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commands using this context can't be overwritten
4 participants