Debugging tips in Jasmine
Saikat Saha
Frontend Developer at PayPal | Oracle | ANZ | JP Morgan - JavaScript, HTML5, CSS3, ReactJS, React Native, MERN, NodeJS, PhoneGap, Cross Platform Mobile, Data Structure, Algorithm, System Design, Full Stack - NodeJS
We all know that Jasmine is a very popular unit testing framework for JavaScript, do we all know that there is something called 'Skipping' and 'Focusing' in Jasmine?
Skipping is basically to skip a particular or a set of test cases which is blocking the test suite or is unnecessary and can applied to both 'describe' and 'it' block, let's have an example with explanations as comments
xdescribe('Test Case - Describe', () => { // you can see that I have added an 'x' before describe which is basically to apply skipping in this block, it will skip all the test cases from execution
xit('Test Case - It',() => { // similar to the describe block, I'm adding 'x' in front of it to get this block skipped during the execution
expect(true).toBe(true);
})
})
Now let's come to the 'Focusing' part, it's kind of reverse to 'Skipping', what I mean to say is, we use it basically to focus on a particular or set of test cases and similar to 'Skipping' it can be applied to both 'describe' and 'it' block with a 'f' in front of it and it will execute only those set of tests in the whole test suite
You can refer the above example by replacing 'xdescribe' with 'fdescribe' and 'xit' with 'fit'