【发布时间】:2018-05-10 11:18:53
【问题描述】:
我正在尝试为使用 Kendo 模板 Html 的函数编写 Karma 测试。
代码如下:
$scope.columns = [{
field: gridColumns.STATUS,
title: gridColumnsTitle.STATUS,
template: $scope.getKendoTemplate($("#statusTemplate").html()),
width: 80
}];
问题在于未定义的 HTML 模板 $("#statusTemplate").html()。
我收到这样的错误:
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)
#statusTemplate 的代码在 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>
有没有办法让这个单元测试通过。无需对实际代码进行太多更改。
【问题讨论】:
标签: unit-testing jasmine karma-jasmine