I am using Mocha with Sinon JS and Phantom Js to test the google analytics call from a particular page. Till now, i am able to execute static test cases for individual element by writing different test case for each element. Like :
describe("Site Home Page Test", function() {
it ("Global Search track", function() {
var link = $('button.search');
link.click();
});
});
Now the ask is, is it possible to execute test case if only $('elem') is found? something like this:
describe("Site Home Page Test", function() {
// if(condition) {
it ("Global Search track", function() {
var link = $('button.search');
link.click();
});
// }
});
Mocha does not run individual tests in parallel. That means if you hand Mocha a single, lonely test file, it will spawn a single worker process, and that worker process will run the file. If you only have one test file, you'll be penalized for using parallel mode. Don't do that.
With its default “BDD”-style interface, Mocha provides the hooks before() , after() , beforeEach() , and afterEach() . These should be used to set up preconditions and clean up after your tests.
You can skip tests by placing an x in front of the describe or it block, or placing a . skip after it. describe('feature 1', function() {}); describe.
I'm not sure if I've missed the question completly, but you can do conditional test cases exactly how you have it written:
describe("Some module", function() {
if(false) {
it ("should NOT run this test case", function() { });
}
it("should run this test case", function() { });
});
mocha will only run the unit-test that isn't in the if-statement.
Some module
✓ should run this test case
1 passing (5 ms)
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