Reputation: 3241
How can I skip the whole set of tests in a spec file only in a specific case? Sample code:
context("Conditional run", () => {
before(() => {
cy.get("div").then($div => {
if (!Cypress.$("div[title='OK']", $comp).length) {
// continue with the tests
} else {
// skip ALL the tests
}
});
});
});
Upvotes: 1
Views: 1790
Reputation: 31862
The beforeEach()
allows skipping.
Try this
context("Conditional run", () => {
let skip = false;
before(() => {
cy.get("div").then(($div) => {
if (!Cypress.$("div[title='OK']", $comp).length) {
skip = false
} else {
skip = true
}
});
});
beforeEach(function() { // use regular function here
if (skip) this.skip();
})
});
It might also work just putting the skip call in the before, since you want to skip all tests.
context("Conditional run", () => {
before(function() { // use regular function here
cy.get("div").then(function($div) { // not sure if function is needed here
if (Cypress.$("div[title='OK']", $comp).length) {
this.skip();
}
});
});
});
Upvotes: 3