0
votes

I am trying to write Karma test for a function which uses a Kendo template Html.

The code goes like this:

$scope.columns = [{ 
    field: gridColumns.STATUS, 
    title: gridColumnsTitle.STATUS, 
    template: $scope.getKendoTemplate($("#statusTemplate").html()), 
    width: 80 
}];

The issue is with HTML template $("#statusTemplate").html() which is undefined. And I get an error like this:

TypeError: Cannot read property 'replace' of undefined
           at Object.compile (app/js/kendo.all.min.js:25:7431)
           at new proxy (wwwroot/lib/jquery/dist/jquery.js:497:14)
           at ChildScope.getKendoTemplate (app/components/test/demo/demo.controller.es5.js:9:22664)

And the code for #statusTemplate goes like this in Html:

<script type="text/x-kendo-template" id="statusTemplate">
        <span data-ng-show="dataItem.active">On</span>
        <span data-ng-show="!dataItem.active">Off</span>
</script>

Is there a way I could get this unit testing passed. Without much changes to the actual code.

1

1 Answers

0
votes

I end up spying on getKendoTemplate,

spyOn($scope,"getKendoTemplate").and.returnValue("");