小编Man*_*uuz的帖子

使用Karma/Jasmine对modalInstance控制器进行单元测试

编辑:本文末尾的快速和肮脏的解决方案

我正在使用AngularUI-Bootstrap中的模态窗口,就像在网站上解释的那样,除了我分割文件.因此我有:

CallingController.js:

$scope.delete = function () {
    if ($scope.selected.length > 0) {
        // [...]
        // preparing data
        // [...]
        var modalInstance = $modal.open({
            templateUrl: 'views/modalView.html',
            controller: 'modalCtrl',
            resolve: {
                itemArray: function () {
                    return $scope.selected;
                }
            }
        });
        modalInstance.result.then(function (confirm) {
            if (confirm === true) {
                // [...]
                // treat
                // [...]
            }
        });
    }
};
Run Code Online (Sandbox Code Playgroud)

modalController.js:

myAppControllers.controller('modalCtrl',
    function ($scope, $modalInstance, itemArray) {

        $scope.accept = function () {
            $modalInstance.close(true);
        };

        $scope.reject = function () {
            $modalInstance.close(false);
        };

        $scope.itemArray = …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs angular-ui-bootstrap karma-runner karma-jasmine

25
推荐指数
2
解决办法
3万
查看次数