Skip to content

Commit

Permalink
Fix duplicate logs on not.exist assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWinds committed Aug 16, 2022
1 parent 7951a02 commit 6849134
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 5 additions & 1 deletion packages/driver/cypress/e2e/commands/assertions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,15 @@ describe('src/cy/commands/assertions', () => {
it('resolves eventually not exist', () => {
const button = cy.$$('button:first')

cy.on('command:retry', _.after(2, _.once(() => {
cy.on('command:retry', _.after(3, _.once(() => {
button.remove()
})))

cy.get('button:first').click().should('not.exist')

cy.then(function () {
assertLogLength(this.logs, 3)
})
})

it('resolves all 3 assertions', (done) => {
Expand Down
24 changes: 12 additions & 12 deletions packages/driver/src/cy/commands/asserting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ export default function (Commands, Cypress, cy, state) {

const applyChainer = function (memo, value) {
logIndex++
if (value === lastChainer && !isCheckingExistence) {
cy.state('onBeforeLog', (log) => {
log.set('command', command)
log.set('commandLogId', `${assertionIndex}-${logIndex}`)
})

try {
if (value === lastChainer && !isCheckingExistence) {
// https://github.com/cypress-io/cypress/issues/16006
// Referring some commands like 'visible' triggers assert function in chai_jquery.js
// It creates duplicated messages and confuses users.
const cmd = memo[value]

cy.state('onBeforeLog', (log) => {
log.set('command', command)
log.set('commandLogId', `${assertionIndex}-${logIndex}`)
})
const cmd = memo[value]

try {
if (_.isFunction(cmd)) {
try {
return cmd.apply(memo, args)
Expand All @@ -126,11 +126,11 @@ export default function (Commands, Cypress, cy, state) {
} else {
return cmd
}
} finally {
cy.state('onBeforeLog', undefined)
} else {
return memo[value]
}
} else {
return memo[value]
} finally {
cy.state('onBeforeLog', undefined)
}
}

Expand Down

0 comments on commit 6849134

Please sign in to comment.