Created
March 22, 2021 18:05
-
-
Save fernyb/30ef00de38ada49d912ce018542be066 to your computer and use it in GitHub Desktop.
Cypress Promises
This file contains hidden or 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
const throwsAnError = function(message) { | |
return new Cypress.Promise((resolve, reject) => { | |
setTimeout(() => { | |
//throw "Emergency! Emergency!" | |
resolve(message); | |
//reject("All American Rejects!"); | |
}, 3500); | |
}); | |
} | |
let message; | |
cy.wrap(throwsAnError("1. First One!")) | |
.then((result) => { | |
expect(result).to.equal("1. First One!"); | |
const person = { | |
name: "Fern" | |
}; | |
return Cypress.Promise.resolve([person, "2. Order fries!"]); | |
}) | |
.then(([person, result]) => { | |
expect(result).to.equal("2. Order fries!"); | |
return new Cypress.Promise((resolve) => { | |
throwsAnError("3. Order milkshake!").then((message) => { | |
person.message = message; | |
resolve([person, message]); | |
}); | |
}); | |
}) | |
.then(([person, result]) => { | |
expect(person.name).to.equal("Fern"); | |
expect(person.message).to.equal(result); | |
expect(result).to.equal("3. Order milkshake!"); | |
return throwsAnError("4."); | |
}) | |
.then((result) => { | |
expect(result).to.equal("4."); | |
return throwsAnError("5."); | |
}) | |
.then((result) => { | |
expect(result).to.equal("5."); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment