As part of my Angular project, I am currently focusing on writing unit test cases using the Jasmine Framework and Karma. To ensure thorough testing coverage, I am utilizing Coverage-html (Istanbul).
When it comes to coverage, there are several important types to consider:
- Function coverage.
- Branch coverage.
- Statement coverage.
- Line coverage.
- Ignored coverage (handled through Istanbul).
I would appreciate an explanation of these different types of coverage and any essential factors that should be taken into account while writing unit test cases:
function setCookie(sessionId) {
if(sessionId) {
setCookie('sessionId', sessionId, 21600);
} else {
setCookie('sessionId', session.getId(), 21600);
}
}
In regard to this function, I have already written some test cases:
describe('setCookie()', function(){
it('should set a cookie without expiration days', function() {
var deferred = $q.defer();
spyOn(sessionCard, 'setCookie').andCallFake(function(){
return deferred.promise;
})
sessionCard.setCookie('sessionId', 'sessionId');
expect(document.cookie).toBeDefined();
expect(document.cookie).toBeTruthy();
});
})