forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-css-spec.js
54 lines (49 loc) · 1.5 KB
/
html-css-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
/// <reference types="Cypress" />
describe('HTML', () => {
it('modifies the page itself', () => {
const style = `
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: pink;
text-align: center;
text-size: large;
padding: 1em;
`
// we are only interested in the HTML root resource
cy.intercept({ pathname: '/' }, (req) => {
req.reply((res) => {
res.body += `<footer style="${style}">⚠️ This is a Cypress test ⚠️</footer>`
})
})
cy.visit('/')
cy.contains('footer', 'Cypress test').should('be.visible')
})
})
describe('CSS', () => {
it('highlights LI elements using injected CSS', () => {
// let's intercept the stylesheet the application is loading
// to highlight list items with a border
cy.intercept('styles.css', (req) => {
// to avoid caching responses and the server responding
// with nothing (because the resource has not changed)
// and force the server to send the CSS file
// delete caching headers from the request
delete req.headers['if-modified-since']
delete req.headers['if-none-match']
req.reply((res) => {
res.send(`${res.body}
li {
border: 1px solid pink;
}
`)
})
})
cy.visit('/')
// confirm the CSS was injected and applied
cy.get('li').should('have.length.gt', 1).first().invoke('css', 'border')
.should('be.a', 'string')
.and('include', 'solid')
})
})