-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.js
71 lines (61 loc) · 1.88 KB
/
spec.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
62
63
64
65
66
67
68
69
70
71
/// <reference types="cypress" />
describe('intercept', () => {
beforeEach(() => {
cy.visit('index.html')
})
it('loads users', () => {
// https://on.cypress.io/route
// note: cy.server and cy.route is deprecated in Cypress v6
// cy.server()
// cy.route('/users?*', 'fixture:users.json').as('users')
// https://on.cypress.io/intercept
cy.intercept({
pathname: '/users',
query: {
_limit: '3'
}
}, {
fixture: 'users.json',
headers: {
'Access-Control-Allow-Origin': '*'
}
}).as('users')
cy.get('#load-users').click()
cy.wait('@users')
cy.get('.user').should('have.length', 3)
})
it('uses minimatch to intercept', () => {
cy.intercept('**/users?*').as('users')
cy.get('#load-users').click()
cy.wait('@users')
})
it('uses minimatch to intercept (2)', () => {
// https://www.npmjs.com/package/minimatch
expect(
Cypress.minimatch(
'https://jsonplaceholder.cypress.io/users?_limit=3',
'**/users?_limit=+(3|5)'
)
, 'Minimatch test'
).to.be.true
cy.intercept('**/users?_limit=+(3|5)').as('users')
cy.get('#load-users').click()
cy.wait('@users').its('response.body').should('have.length', 3)
// intercepts _limit=5 requests
cy.get('#load-five-users').click()
cy.wait('@users').its('response.body').should('have.length', 5)
})
it('uses substring to intercept', () => {
cy.intercept('_limit=3').as('users')
cy.get('#load-users').click()
cy.wait('@users')
})
it('uses regexp to intercept', () => {
cy.intercept(/\/users\?_limit=(3|5)$/).as('users')
cy.get('#load-users').click()
cy.wait('@users').its('response.body').should('have.length', 3)
// intercepts _limit=5 requests
cy.get('#load-five-users').click()
cy.wait('@users').its('response.body').should('have.length', 5)
})
})