-
Notifications
You must be signed in to change notification settings - Fork 2
/
if.cy.js
61 lines (56 loc) · 1.45 KB
/
if.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/// <reference path="../../src/index.d.ts" />
import 'cypress-if'
import '../../src'
import './utils'
beforeEach(() => {
cy.visit('cypress/index.html')
cy.intercept({
pathname: '/users',
}).as('users')
})
describe('waitIfHappens', () => {
describe('in combination with cypress-if', () => {
it('the call happens', () => {
cy.get('h1').should('be.visible').makeAppRequest(500)
cy.waitIfHappens('@users', 1000)
.if()
.log('call has happened')
.else()
.log('no call')
})
it('the call happens and yields the intercept', () => {
cy.get('h1').should('be.visible').makeAppRequest(1500)
cy.waitIfHappens('@users', 2000)
.if()
.its('response.body')
.should('have.length', 3)
.else()
.log('no call')
})
it('the call never happens', () => {
cy.get('h1').should('be.visible')
cy.waitIfHappens('@users', 1000)
.if()
.log('call has happened')
.else()
.log('no call')
})
it('prints the number of users', () => {
cy.get('h1')
.should('be.visible')
// comment out to see the ".if()" skip
// the rest of the commands
.makeAppRequest(500, 5)
cy.waitIfHappens({
alias: '@users',
timeout: 2000,
yieldResponseBody: true,
})
.if()
.its('length')
.then((n) => {
cy.log(`got ${n} users`)
})
})
})
})