From 4630ef49d846de529e85372fe892fd6a537fe1a6 Mon Sep 17 00:00:00 2001 From: Hugo Hache Date: Thu, 2 Dec 2021 18:22:10 +0100 Subject: [PATCH] fix: set the context when overwriting .clock command (#19158) Co-authored-by: Ryan Manuel Co-authored-by: Ryan Manuel --- .../driver/cypress/integration/commands/clock_spec.js | 8 ++++++++ packages/driver/src/cy/commands/clock.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/driver/cypress/integration/commands/clock_spec.js b/packages/driver/cypress/integration/commands/clock_spec.js index 44ab1cdaf5..01ade377b6 100644 --- a/packages/driver/cypress/integration/commands/clock_spec.js +++ b/packages/driver/cypress/integration/commands/clock_spec.js @@ -125,6 +125,14 @@ describe('src/cy/commands/clock', () => { }) }) + it('overwrites without crashing', () => { + Cypress.Commands.overwrite('clock', (originalCommand, ...args) => { + return originalCommand(...args) + }) + + cy.clock() + }) + context('errors', () => { it('throws if now is not a number (or options object)', (done) => { cy.on('fail', (err) => { diff --git a/packages/driver/src/cy/commands/clock.ts b/packages/driver/src/cy/commands/clock.ts index 9e5126275d..128634c50b 100644 --- a/packages/driver/src/cy/commands/clock.ts +++ b/packages/driver/src/cy/commands/clock.ts @@ -39,7 +39,7 @@ export default function (Commands, Cypress, cy, state) { return Commands.addAll({ type: 'utility' }, { clock (subject, now, methods, options = {}) { let userOptions = options - const ctx = this + const ctx = state('ctx') if (clock) { return clock