0

I am writing the test cases of my application using karma and jasmine. I am new in unit testing. Here is my code:

$scope.$watch('filterParams.statusModel', function() {
        $scope.customFilters.statusArray = customFilters.statusArray.filter(function(_i) {
            var _x = $scope.filterParams.statusModel.toLowerCase();
            if (_i.value.toLowerCase().indexOf(_x) !== -1) {
                return true;
            }
            return false
        })
    });

Test case is:

it('\n Watch function fire continously', function () {
                scope.customFilters = {
                statusArray: [{value:'Active'},{value:'InActive'}],
                status:[{'active':true},{'InActive':true}]
            }
            scope.filterParams = {};
            scope.filterParams.statusModel = 'Active'
            scope.$apply()
            scope.filterParams.statusModel = 'InActive'
            scope.$apply()
        });

It does not show any error and test case run succesfully,but in code coverage it show me red, that means your code is not covered

rave
  • 1,022
  • 1
  • 12
  • 23
Karan
  • 1,048
  • 2
  • 20
  • 38

1 Answers1

0

You don't have any expects so maybe this is why your code coverage does not increase. You should have something like this:

expect(scope.customFilters.statusArray).toBe([{value: "Active"}]);

rave
  • 1,022
  • 1
  • 12
  • 23