-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: have.value assertions, closes #23
- Loading branch information
Showing
3 changed files
with
91 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/// <reference types="cypress" /> | ||
// @ts-check | ||
|
||
import '../../src' | ||
|
||
describe('Input element', () => { | ||
it('types again if the value was corrupted', () => { | ||
cy.visit('cypress/funky-input.html') | ||
cy.get('#name') | ||
.type('Cypress', { delay: 20 }) | ||
.if('not.have.value', 'Cypress') | ||
.clear() | ||
.type('Cypress') | ||
.else() | ||
.log('Input has expected value') | ||
.finally() | ||
.should('have.value', 'Cypress') | ||
}) | ||
|
||
it('have.value positive', () => { | ||
cy.wrap(Cypress.$('<input value="foo" >')) | ||
.if('have.value', 'foo') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@if').should('be.calledOnce') | ||
cy.get('@else').should('not.be.called') | ||
}) | ||
|
||
it('have.value negative', () => { | ||
cy.wrap(Cypress.$('<input value="foo" >')) | ||
.if('have.value', 'bar') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('be.calledOnce') | ||
cy.get('@if').should('not.be.called') | ||
}) | ||
|
||
it('have.value positive', () => { | ||
cy.wrap(Cypress.$('<input value="foo" >')) | ||
.if('have.value', 'foo') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@if').should('be.calledOnce') | ||
cy.get('@else').should('not.be.called') | ||
}) | ||
|
||
context('not.have.value', () => { | ||
it('positive', () => { | ||
cy.wrap(Cypress.$('<input value="foo" >')) | ||
.if('not.have.value', 'foo') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@else').should('be.calledOnce') | ||
cy.get('@if').should('not.be.called') | ||
}) | ||
|
||
it('negative', () => { | ||
cy.wrap(Cypress.$('<input value="foo" >')) | ||
.if('not.have.value', 'bar') | ||
.then(cy.spy().as('if')) | ||
.else() | ||
.then(cy.spy().as('else')) | ||
cy.get('@if').should('be.calledOnce') | ||
cy.get('@else').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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<body> | ||
<input id="name" /> | ||
<p>Your name?</p> | ||
<script> | ||
setTimeout(() => { | ||
// clear the input box suddenly | ||
document.getElementById('name').value = '' | ||
}, Math.random() * 30 + 70) | ||
</script> | ||
</body> |
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