diff --git a/cypress/e2e/alias.cy.js b/cypress/e2e/alias.cy.js new file mode 100644 index 0000000..3b7ffea --- /dev/null +++ b/cypress/e2e/alias.cy.js @@ -0,0 +1,31 @@ +/// +// @ts-check + +import '../../src' + +describe('aliases', () => { + it('has an existing alias', () => { + cy.wrap(42).as('answer') + cy.get('@answer') + .if('exist') + .log('alias exists') + .then(cy.spy().as('if')) + .else() + .then(cy.spy().as('else')) + cy.get('@if').should('have.been.called') + cy.get('@else').should('not.have.been.called') + }) + + // SKIP: https://github.com/bahmutov/cypress-if/issues/35 + it.skip('has no alias', () => { + // notice there is no alias with the name "answer" + cy.get('@answer') + .if('exist') + .log('alias exists') + .then(cy.spy().as('if')) + .else() + .then(cy.spy().as('else')) + cy.get('@if').should('have.been.called') + cy.get('@else').should('not.have.been.called') + }) +}) diff --git a/src/index.js b/src/index.js index e50825c..6bccc7f 100644 --- a/src/index.js +++ b/src/index.js @@ -102,6 +102,9 @@ Cypress.Commands.add( } catch (e) { console.error(e) assertionsPassed = false + if (e.message.includes('Invalid Chai property')) { + throw e + } } } }