-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
spec.cy.js
29 lines (26 loc) · 1.04 KB
/
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
/// <reference types="cypress" />
describe('Page source', () => {
Cypress.on('uncaught:exception', (err) => {
// cypress.io has a few React exceptions related to state hydration,
// but these exceptions do not impact this test
// This is also true with Cannot read properties of null (reading 'addEventListener') which has to due with the osano library
// that is on www.cypress.io
if (err.message.includes('Minified React error') || err.message.includes(`Cannot read properties of null (reading 'addEventListener')`)) {
return false
}
return true
})
it('gets the currently loaded document HTML', () => {
cy.visit('/')
cy.document().its('documentElement.outerHTML')
.should('be.a', 'string')
// let's show the HTML as text right in the browser
// we need to sanitize the "<", ">", "&" characters
.invoke('replace', /&/g, '&')
.invoke('replace', /</g, '<')
.invoke('replace', />/g, '>')
.then((sanitized) => {
cy.document().invoke('write', sanitized)
})
})
})