【问题标题】:How to Unit test Angular Extend如何对 Angular Extend 进行单元测试
【发布时间】:2015-10-14 12:11:29
【问题描述】:

我有一个使用角度扩展的控制器。 如何测试角度延伸?

angular.module('conditionmonitor').controller('mapController', ['$scope', '$http', 'UIConfig', function ($scope, $http, UIConfig) {
    angular.extend($scope, {
        center: {
            lat: UIConfig.LATITUTE,
            lng: UIConfig.LONGITUDE,
            zoom: UIConfig.ZOOMLEVEL
        },
        markers: $scope.markers,
        layers: $scope.layers,
        defaults: {
            scrollWheelZoom: true
        }
    });

【问题讨论】:

  • 您不必测试 angular.extend。单元测试旨在测试您的控制器所做的事情,在这种情况下,它将值置于范围内。因此,您应该测试给定的条件,您应该在范围内具有预期值。如果有意义,您也可以将其用于服务 - 它有时也可以帮助您进行测试。

标签: angularjs unit-testing karma-mocha


【解决方案1】:

当您编写单元测试时,您并不是要测试第三方库的功能,而只是测试您自己编写的功能。

假设您正在使用的第 3 方库确实已经过测试 (which is true for angularjs)

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 2020-05-10
    • 2018-01-05
    • 2018-07-16
    • 2017-12-27
    相关资源
    最近更新 更多