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>
This commit is contained in:
Hugo Hache
2021-12-02 18:22:10 +01:00
committed by GitHub
parent 42dfb8abb1
commit 4630ef49d8
2 changed files with 9 additions and 1 deletions

View File

@@ -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) => {

View File

@@ -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