forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header-spec.js
41 lines (37 loc) · 1.43 KB
/
header-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
/// <reference types="Cypress" />
describe('intercept', { viewportHeight: 300 }, () => {
it('returns standard headers', () => {
cy.visit('/headers')
cy.get('#get-headers').click()
// no custom headers
cy.contains('#output', 'accept-language')
.should('not.contain', 'x-custom-header')
})
it('adds request header', () => {
cy.visit('/headers')
cy.intercept('/req-headers', (req) => {
// note: this header will NOT be shown in the browser's
// Network tab, as the request has already left the browser
// when this header is added
req.headers['x-custom-headers'] = 'added by cy.intercept'
})
cy.get('#get-headers').click()
cy.contains('#output', 'accept-language')
.should('contain', 'x-custom-header')
.and('contain', 'added by cy.intercept')
})
it('adds request header', () => {
cy.visit('/headers')
cy.intercept('/req-headers', (req) => {
// note: this header will NOT be shown in the browser's
// Network tab, as the request has already left the browser
// when this header is added
req.headers['x-custom-headers'] = 'added by cy.intercept'
}).as('headers')
cy.get('#get-headers').click()
// but the custom request header added by the intercept
// will be in object we can get by waiting on the intercept
cy.wait('@headers').its('request.headers')
.should('have.property', 'x-custom-headers', 'added by cy.intercept')
})
})