【问题标题】:Karma Jasmine unit test for Kendo templateKendo 模板的 Karma Jasmine 单元测试
【发布时间】: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


    【解决方案1】:

    我最终监视了 getKendoTemplate,

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

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 1970-01-01
      • 2017-09-15
      • 2016-06-24
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多