Skip to content

Commit 35be2ae

Browse files
feat: Add user's log option to cy.tick (#15586)
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
1 parent e41cfc1 commit 35be2ae

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cli/types/cypress.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ declare namespace Cypress {
18721872
* // or use this shortcut
18731873
* cy.tick(5000).invoke('restore')
18741874
*/
1875-
tick(milliseconds: number): Chainable<Clock>
1875+
tick(milliseconds: number, options?: Partial<Loggable>): Chainable<Clock>
18761876

18771877
/**
18781878
* Get the `document.title` property of the page that is currently active.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ describe('src/cy/commands/clock', () => {
461461
expect(log.get('snapshots')[1].name).to.equal('after')
462462
})
463463
})
464+
465+
it('does not emit when {log: false}', () => {
466+
cy
467+
.clock()
468+
.tick(10, { log: false })
469+
.then(function () {
470+
expect(this.logs[0]).to.be.undefined
471+
})
472+
})
464473
})
465474
})
466475
})

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = function (Commands, Cypress, cy, state) {
9797

9898
const { tick } = clock
9999

100-
clock.tick = function (ms) {
100+
clock.tick = function (ms, options = {}) {
101101
if ((ms != null) && !_.isNumber(ms)) {
102102
$errUtils.throwErrByPath('tick.invalid_argument', { args: { arg: JSON.stringify(ms) } })
103103
}
@@ -106,10 +106,14 @@ module.exports = function (Commands, Cypress, cy, state) {
106106
ms = 0
107107
}
108108

109-
const theLog = log('tick', `${ms}ms`, false, {
110-
'Now': clock.details().now + ms,
111-
'Ticked': `${ms} milliseconds`,
112-
})
109+
let theLog
110+
111+
if (options.log !== false) {
112+
theLog = log('tick', `${ms}ms`, false, {
113+
'Now': clock.details().now + ms,
114+
'Ticked': `${ms} milliseconds`,
115+
})
116+
}
113117

114118
if (theLog) {
115119
theLog.snapshot('before', { next: 'after' })
@@ -151,12 +155,12 @@ module.exports = function (Commands, Cypress, cy, state) {
151155
return clock
152156
},
153157

154-
tick (subject, ms) {
158+
tick (subject, ms, options = {}) {
155159
if (!clock) {
156160
$errUtils.throwErrByPath('tick.no_clock')
157161
}
158162

159-
clock.tick(ms)
163+
clock.tick(ms, options)
160164

161165
return clock
162166
},

0 commit comments

Comments
 (0)