Currently, I have some test cases that I only want to execute in certain conditions.
it ('user is able to log in', function() {
if(siteAllowsLogin) {
.....
}
Using the above syntax results in sitesNotAllowingLogin to PASS this test. I know there is a solution to mark the test as PENDING, but I would rather the test did not show, if it was not applicable.
I also want to keep the logic inside of the test case, if possible. So keeping the if block inside the test case.
Any suggestions on how to skip this test if the condition is not met so that it does not display on the results as PENDING or PASSED.
Help would be greatly appreciated.
You could use an ignore
function in front to suppress the test if the provided predicate/state is true:
var ignore = function(exp){return{it:((typeof exp==='function')?exp():exp)?function(){}:it}};
describe('Suite 1', function() {
it("test a", function() {
expect(1).toEqual(1);
});
ignore(true).it("test b", function() {
expect(1).toEqual(1);
});
ignore(skip).it("test c", function() {
expect(1).toEqual(1);
});
function skip(){
return true;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With