Covering the branch code : Karma & Angular

1.2k Views Asked by At

I am trying my hands at testing with karma-jasmine. I am getting a yellow indication showing Branch is not covered for the following code.

I have posted the test case for the same as well.

Can anyone help me cover the test case for the branch?

enter image description here

const mockResponseRecommendation = { 
    status: 'success', 
    data: [ 
      { 
        resourceId: 10, 
        notes: null, 
        typeOfDelay: 'Time', 
        recommendationDate: '11/28/2021', 
        minValue: 5, 
      }, 
    ], 
  }; 
1

There are 1 best solutions below

0
mohamed 102 On

I had the same problems as you. Whenever I encounter this situation I usually dont try to test this branch but instead mofifying my code to remove this branch. Because you dont have a code to run if this response.data and this.highAlertinfo doesnt exist, you can just put those in a variable and use the as keyword. For example, if response.data is a number you can add before the first if: const dataResponse = response.data as number and the use the newly created variable instead same thing for the other uncovered branch.