Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for callback functions (#29)
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @ts-check | ||
|
||
import '../../src' | ||
|
||
describe('assertion callback function', () => { | ||
context('predicate', () => { | ||
const isEven = (n) => n % 2 === 0 | ||
|
||
it('if branch', () => { | ||
cy.wrap(42) | ||
.if(isEven) | ||
.log('even') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.log('odd') | ||
.then(cy.spy().as('else')) | ||
cy.get('@if').should('have.been.called') | ||
cy.get('@else').should('not.be.called') | ||
}) | ||
|
||
it('else branch', () => { | ||
cy.wrap(1) | ||
.if(isEven) | ||
.log('even') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.log('odd') | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('have.been.called') | ||
cy.get('@if').should('not.be.called') | ||
}) | ||
}) | ||
|
||
context('Chai assertion', () => { | ||
const is42 = (n) => expect(n).to.equal(42) | ||
|
||
it('if branch', () => { | ||
cy.wrap(42) | ||
.if(is42) | ||
.log('even') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.log('odd') | ||
.then(cy.spy().as('else')) | ||
cy.get('@if').should('have.been.called') | ||
cy.get('@else').should('not.be.called') | ||
}) | ||
|
||
it('else branch', () => { | ||
cy.wrap(1) | ||
.if(is42) | ||
.log('even') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.log('odd') | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('have.been.called') | ||
cy.get('@if').should('not.be.called') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters