I am trying to write tests for features that aren't enabled yet (hidden behind feature flag); There's an endpoint I can call to check if the application feature flag is turned on or off and I wrote a function to do so.
My next task is to implement a way for Cypress to only run specific tests if the feature flag is ON. How do I implement that leveraging the method I wrote? Is there a check I have to implement somewhere in the Cypress.config?
Thanks!
code for the method
checkTemplateFeatureFlag(): Chainable<Temp> {
return (new Cypress.Promise(resolve => {
cy.request({
method: 'GET',
url: `ENDPOINT_HERE`
}).then(resp => {
const array = JSON.parse(resp.body);
const foundFlag = !!array.find(
(obj: { flag_name: string; active: boolean }) =>
obj.flag_name === 'FLAG_NAME' && obj.active
);
resolve(foundFlag);
});
}) as unknown) as Chainable<Temp>;
}
A simple way to skip tests (or
describe
blocks) dynamically is to usefunction()
form callbacks to accessthis
, then conditionally callthis.skip()
.You will also need to call
checkTemplateFeatureFlag()
in a separate block, say abeforeEach()
, since it has async internals.