Skip to content

Commit

Permalink
fix: do not log undefined cy.else message
Browse files Browse the repository at this point in the history
* fix: do not log undefined cy.else message

* fix the v11
  • Loading branch information
bahmutov authored Oct 23, 2024
1 parent 5a24122 commit 4a0e558
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cypress/e2e/else.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe('else branch', () => {
cy.wrap(42).if('equal', 1).log('if branch').else(42)
})

it('logs the else message', () => {
cy.spy(cy, 'log').as('log')
cy.wrap(true).if('false').else('else branch')
cy.get('@log').should('have.been.calledWith', 'else branch')
})

it('logs the default else message', () => {
cy.spy(cy, 'log').as('log')
cy.wrap(true).if('false').else()
cy.get('@log').should('not.have.been.called')
})

it('can have multiple if-else', () => {
cy.wrap(1)
.if('equal', 2)
Expand Down
2 changes: 1 addition & 1 deletion src/index-v11.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Cypress.Commands.add('else', { prevSubject: true }, (subject, text) => {
// find the subject from the "if()" before
subject = findMyIfSubject(cy.state('current').attributes)
}
if (typeof text !== undefined) {
if (typeof text !== 'undefined') {
cy.log(text)
}
if (subject) {
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ if (major < 12) {
// find the subject from the "if()" before
subject = findMyIfSubject(cy.state('current').attributes)
}
if (typeof text !== undefined) {
if (typeof text !== 'undefined') {
cy.log(text)
} else {
debug('nothing to log for else branch')
}
if (subject) {
cy.wrap(subject, { log: false })
Expand Down

0 comments on commit 4a0e558

Please sign in to comment.