Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: explain combining assertions (#30)
* add AND OR assertion callback functions spec * add callback function to the README * document combining assertions
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
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
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,86 @@ | ||
/// <reference types="cypress" /> | ||
// @ts-check | ||
|
||
import '../../src' | ||
|
||
describe('AND assertions', () => { | ||
context('uses && inside the predicate callback', () => { | ||
it('T && T', () => { | ||
cy.wrap(42) | ||
.if((n) => n > 20 && n < 50) | ||
.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') | ||
}) | ||
|
||
it('T && F', () => { | ||
cy.wrap(42) | ||
.if((n) => n > 20 && n < 40) | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('have.been.called') | ||
cy.get('@if').should('not.have.been.called') | ||
}) | ||
}) | ||
|
||
context('uses Chai assertions', () => { | ||
it('ok and ok', () => { | ||
cy.wrap(42) | ||
.if((n) => expect(n).to.be.greaterThan(20).and.to.be.lessThan(50)) | ||
.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') | ||
}) | ||
|
||
it('ok and not ok', () => { | ||
cy.wrap(42) | ||
.if((n) => expect(n).to.be.greaterThan(20).and.to.be.lessThan(40)) | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('have.been.called') | ||
cy.get('@if').should('not.have.been.called') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('OR assertions', () => { | ||
context('uses || inside the predicate callback', () => { | ||
it('T || F', () => { | ||
cy.wrap(42) | ||
.if((n) => n > 20 || n < 10) | ||
.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') | ||
}) | ||
|
||
it('F || T', () => { | ||
cy.wrap(42) | ||
.if((n) => n > 200 || n < 50) | ||
.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') | ||
}) | ||
|
||
it('F || F', () => { | ||
cy.wrap(42) | ||
.if((n) => n > 200 || n < -40) | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('have.been.called') | ||
cy.get('@if').should('not.have.been.called') | ||
}) | ||
}) | ||
|
||
// note that we cannot easily do OR using Chai assertions | ||
}) |