javascript - Karma-coverage not recognizing branch test -


my karma-coverage report states 'else' branch not covered in below example, tested. ideas why karma-coverage not recognizing test?

utilities.service.js:

function formatvalue(value, form) {    if (form === '2') {     valueformatted = twodecimals(value);   } else if (form === '4') {     valueformatted = fourdecimals(value);   }    return valueformatted + '!'; } 

utilitiesservicespec.js:

describe('format values', function() {   var formattedvalue;   var value;   var form;    it('should format 2 decimal places', function() {     value = 100;     form = '2';     formattedvalue = utilitiesservice.formatvalue(value, form);     expect(formattedvalue).toequal('100.00!');   });    it('should format 4 decimal places', function() {     value = 100;     form = '4';     formattedvalue = utilitiesservice.formatvalue(value, form);     expect(formattedvalue).toequal('100.0000!');   }); }); 

actually karma-coverage correct. missed test else branch.

describe( 'format values', function() { var formattedvalue; var value; var form; // test if (form === '2') it( 'should format 2 decimal places', function() {     value = 100;     form = '2';     formattedvalue = utilitiesservice.formatvalue( value, form );     expect( formattedvalue ).toequal( '100.00!' ); } );  // test else if (form === '4') it( 'should format 4 decimal places', function() {     value = 100;     form = '4';     formattedvalue = utilitiesservice.formatvalue( value, form );     expect( formattedvalue ).toequal( '100.0000!' ); } ); //will test else it( 'should test if value should not formatted decimal if form other 2 , 4', function() {     value = 100;     form = '5';     formattedvalue = utilitiesservice.formatvalue( value, form );     expect( formattedvalue ).toequal( '100!' ); } );} ); 

considering utilities.service.js be

function formatvalue( value, form ) { var valueformatted = value; if ( form === '2' ) {     valueformatted = twodecimals( value ); } else if ( form === '4' ) {     valueformatted = fourdecimals( value ); }  return valueformatted + '!';} 

or

function formatvalue( value, form ) { var valueformatted; if ( form === '2' ) {     valueformatted = twodecimals( value ); } else if ( form === '4' ) {     valueformatted = fourdecimals( value ); } else {     valueformatted = value; }  return valueformatted + '!';} 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -