diff --git a/packages/driver/src/cy/commands/agents.ts b/packages/driver/src/cy/commands/agents.ts index d16cdc4033a5..baccb0320ca5 100644 --- a/packages/driver/src/cy/commands/agents.ts +++ b/packages/driver/src/cy/commands/agents.ts @@ -46,11 +46,6 @@ const onInvoke = function (Cypress, obj, args) { const { agent } = obj const agentName = agent._cyName - // bail if we've turned off logging this agent - if (agent._log === false) { - return - } - // fakes are children of the agent created with `withArgs` const fakes = agent.matchingFakes(args) @@ -59,6 +54,11 @@ const onInvoke = function (Cypress, obj, args) { fake._cyLog.set('callCount', fake.callCount) } + // bail if we've turned off logging this agent + if (agent._log === false) { + return + } + const logProps = { name: agentName, message: obj.message, diff --git a/packages/runner/cypress/fixtures/issues/issue-18042.js b/packages/runner/cypress/fixtures/issues/issue-18042.js new file mode 100644 index 000000000000..d7ac3d5d3246 --- /dev/null +++ b/packages/runner/cypress/fixtures/issues/issue-18042.js @@ -0,0 +1,9 @@ +it('test', () => { + const obj = { + foo () {}, + } + const stub = cy.stub(obj, 'foo').log(false).as('foo') + + obj.foo('foo', 'bar') + expect(stub).to.be.called +}) diff --git a/packages/runner/cypress/integration/issues/issue-18042.js b/packages/runner/cypress/integration/issues/issue-18042.js new file mode 100644 index 000000000000..a668a281a131 --- /dev/null +++ b/packages/runner/cypress/integration/issues/issue-18042.js @@ -0,0 +1,16 @@ +const helpers = require('../../support/helpers') + +const { createCypress } = helpers +const { runIsolatedCypress } = createCypress() + +// https://github.com/cypress-io/cypress/issues/18042 +describe('issue 18042', () => { + beforeEach(function () { + return runIsolatedCypress(`cypress/fixtures/issues/issue-18042.js`) + }) + + it('Call count is shown even if cy.stub().log(false)', function () { + cy.contains('Spies / Stubs (1)').click() + cy.get('.call-count').eq(1).should('have.text', '1') + }) +})