forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intercept-events.spec.cy.js
43 lines (40 loc) · 1.21 KB
/
intercept-events.spec.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
describe('intercept', () => {
beforeEach(() => {
cy.intercept('/fruits', (req) => {
req.on('before:response', (res) => {
/**
* Emitted before `response` and before any `req.continue`
* handlers. Modifications to `res` will be applied to the
* incoming response.
*/
if (req.headers['x-destroy-response']) {
req.destroy()
}
if (req.headers['x-fail-response']) {
res.send({ fixture: 'failure.json' })
}
})
req.on('response', (res) => {
/**
* Emitted after `before:response` and after any
* `req.continue` handlers - before the response is sent
* to the browser. Modifications to `res` will be applied
* to the incoming response.
*/
if (req.headers['x-mobile-user']) {
res.throttleKbps(3000)
}
})
req.on('after:response', (res) => {
/**
* Emitted once the response to a request has finished
* sending to the browser. Modifications to `res` have no
* impact.
*/
if (req.headers['x-redirect-user']) {
expect(res.statusCode).to.equal(302)
}
})
})
})
})