Skip to content

Commit

Permalink
fix: Allow 'this' to be used in overridden commands (#18899)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue F authored Nov 22, 2021
1 parent 2a471d6 commit 5dc6c88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/driver/cypress/integration/cypress/cy_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,20 @@ describe('driver/src/cypress/cy', () => {
expect(cy.state('current').get('prev').get('args')[0].foo).to.equal('foo')
})
})

// https://github.com/cypress-io/cypress/issues/18892
it('passes this through to overwritten command', () => {
Cypress.Commands.add('bar', function () {
expect(this.test.title).to.exist
})

cy.bar()

Cypress.Commands.overwrite('bar', function (originalFn) {
return originalFn.call(this)
})

cy.bar()
})
})
})
4 changes: 2 additions & 2 deletions packages/driver/src/cypress/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
// store the backup again now
commandBackups[name] = original

const originalFn = (...args) => {
function originalFn (...args) {
const current = state('current')
let storedArgs = args

Expand All @@ -68,7 +68,7 @@ export default {

current.set('args', storedArgs)

return original.fn(...args)
return original.fn.apply(this, args)
}

const overridden = _.clone(original)
Expand Down

3 comments on commit 5dc6c88

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5dc6c88 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/circle-develop-5dc6c88ed535126e6d2b6452a7ff8e1cd59503a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5dc6c88 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/appveyor-develop-5dc6c88ed535126e6d2b6452a7ff8e1cd59503a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5dc6c88 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/circle-develop-5dc6c88ed535126e6d2b6452a7ff8e1cd59503a2/cypress.tgz

Please sign in to comment.