-
Notifications
You must be signed in to change notification settings - Fork 12
/
exists.cy.js
40 lines (35 loc) · 1021 Bytes
/
exists.cy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// <reference types="cypress" />
// @ts-check
import '../../src'
beforeEach(() => {
cy.visit('cypress/index.html')
})
it('checks an element that exists', () => {
cy.get('#fruits')
.if('exist')
.then(cy.spy().as('if'))
.else()
.then(cy.spy().as('else'))
cy.get('@if').should('have.been.calledOnce')
cy.get('@else').should('not.have.been.called')
})
it('checks an element that does not exists', () => {
cy.get('#not-found')
.if('exist')
.then(cy.spy().as('if'))
.else()
.then(cy.spy().as('else'))
cy.get('@else').should('have.been.calledOnce')
cy.get('@if').should('not.have.been.called')
})
// https://github.com/bahmutov/cypress-if/issues/45
it('checks an element that does not exists using not.exist', () => {
cy.get('#not-found').should('not.exist')
cy.get('#not-found')
.if('not.exist')
.then(cy.spy().as('if'))
.else()
.then(cy.spy().as('else'))
cy.get('@if').should('have.been.calledOnce')
cy.get('@else').should('not.have.been.called')
})