Created
June 21, 2019 18:01
-
-
Save trescenzi/4a8d8d980a78004672cc90e306122ce8 to your computer and use it in GitHub Desktop.
Writing a file upon test fail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('test, () => { | |
it('should do the same thing it did last time', () => { | |
const snapshot = cy.readFile('./cypress/snapshots/snapshot.html'); | |
let bodyHtml = ''; | |
cy.visit('/home'); | |
cy.get('body').then(b => bodyHtml = b.innerHTML); | |
cy.on('fail', () => { | |
// This throws a "You can't promise inside a promise" | |
// https://on.cypress.io/returning-promise-and-commands-in-another-command | |
cy.writeFile('./cypress/snapshots/snapshot.html', bodyHtml); | |
}); | |
cy.on('test:after:run', () => { | |
// This never runs | |
cy.writeFile('./cypress/snapshots/snapshot.html', bodyHtml); | |
}); | |
cy.wrap(null).should(() => { | |
expect(bodyHtml).to.be(snapshot); | |
}); | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('test, () => { | |
it('should do the same thing it did last time', () => { | |
const snapshot = cy.readFile('./cypress/snapshots/snapshot.html'); | |
let bodyHtml = ''; | |
cy.visit('/home'); | |
cy.get('body').then(b => bodyHtml = b.innerHTML); | |
cy.on('test:after:run', () => { | |
// This never runs | |
cy.writeFile('./cypress/snapshots/snapshot.html', bodyHtml); | |
}); | |
cy.wrap(null).should(() => { | |
expect(bodyHtml).to.be(snapshot); | |
}); | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('test, () => { | |
it('should do the same thing it did last time', () => { | |
const snapshot = cy.readFile('./cypress/snapshots/snapshot.html'); | |
let bodyHtml = ''; | |
cy.visit('/home'); | |
cy.get('body').then(b => bodyHtml = b.innerHTML); | |
cy.wrap(null).should(() => { | |
expect(bodyHtml).to.be(snapshot); | |
}).then(() => { | |
// This never runs | |
cy.writeFile('./cypress/snapshots/snapshot.html', bodyHtml); | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment