Skip to content

Commit 4630ef4

Browse files
fix: set the context when overwriting .clock command (#19158)
Co-authored-by: Ryan Manuel <ryanm@cypress.io> Co-authored-by: Ryan Manuel <rfmanuel@gmail.com>
1 parent 42dfb8a commit 4630ef4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/driver/cypress/integration/commands/clock_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ describe('src/cy/commands/clock', () => {
125125
})
126126
})
127127

128+
it('overwrites without crashing', () => {
129+
Cypress.Commands.overwrite('clock', (originalCommand, ...args) => {
130+
return originalCommand(...args)
131+
})
132+
133+
cy.clock()
134+
})
135+
128136
context('errors', () => {
129137
it('throws if now is not a number (or options object)', (done) => {
130138
cy.on('fail', (err) => {

packages/driver/src/cy/commands/clock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function (Commands, Cypress, cy, state) {
3939
return Commands.addAll({ type: 'utility' }, {
4040
clock (subject, now, methods, options = {}) {
4141
let userOptions = options
42-
const ctx = this
42+
const ctx = state('ctx')
4343

4444
if (clock) {
4545
return clock

0 commit comments

Comments
 (0)