From 4a0e558f48303d1e2334765625edff862511370f Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 23 Oct 2024 09:18:37 -0400 Subject: [PATCH] fix: do not log undefined cy.else message * fix: do not log undefined cy.else message * fix the v11 --- cypress/e2e/else.cy.js | 12 ++++++++++++ src/index-v11.js | 2 +- src/index.js | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/else.cy.js b/cypress/e2e/else.cy.js index 897385b..b87bf12 100644 --- a/cypress/e2e/else.cy.js +++ b/cypress/e2e/else.cy.js @@ -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) diff --git a/src/index-v11.js b/src/index-v11.js index 3f16959..4c16e6e 100644 --- a/src/index-v11.js +++ b/src/index-v11.js @@ -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) { diff --git a/src/index.js b/src/index.js index 3146acc..277ab64 100644 --- a/src/index.js +++ b/src/index.js @@ -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 })