-
Notifications
You must be signed in to change notification settings - Fork 14
/
vary-responses-spec.js
64 lines (54 loc) · 1.72 KB
/
vary-responses-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
// @ts-check
describe('TodoMVC', () => {
it('returns zero, one, two, and three items', () => {
// we will visit the page four times, and each time
// the cy.intercept will response with a different fixture
// all the Ajax calls we want to intercept
// have the same pattern
const matchAllTodos = {
method: 'POST',
url: '/',
headers: {
'x-gql-operation-name': 'allTodos',
},
// we will use each response just once
times: 1,
}
// Note: if multiple intercepts match,
// then Cypress applies them from the last to the first one
// thus we define the one-time intercepts from the last to the first
// the fourth request
cy.intercept(matchAllTodos, {
fixture: 'three.json',
}).as('fourth')
// third request
cy.intercept(matchAllTodos, {
fixture: 'two.json',
}).as('third')
// on the second request to fetch all items,
// respond with a fixture with one item
// again, use this intercept just once
cy.intercept(matchAllTodos, {
fixture: 'one.json',
}).as('second')
// on the very first request, respond with and empty list
// but only use this interceptor once
cy.intercept(matchAllTodos, {
fixture: 'zero.json',
}).as('first')
// confirm each request is intercepted
// and a different fixture is used
cy.visit('/')
cy.wait('@first')
cy.get('.todo').should('not.exist').wait(3000)
cy.reload()
cy.wait('@second')
cy.get('.todo').should('have.length', 1).wait(3000)
cy.reload()
cy.wait('@third')
cy.get('.todo').should('have.length', 2).wait(3000)
cy.reload()
cy.wait('@fourth')
cy.get('.todo').should('have.length', 3).wait(3000)
})
})