Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 测试js指令?_Javascript_Angularjs_Testing - Fatal编程技术网

Javascript 测试js指令?

Javascript 测试js指令?,javascript,angularjs,testing,Javascript,Angularjs,Testing,如何测试此角度测试指令 $scope.cancel = function () { $('#pp_bsktexit').modal('show'); }; 像这样的东西,我可以测试,它似乎不太: var nextScreenPath='C_HIST' $scope.goBack = function() { //sessionService.save($scope.sessionData);

如何测试此角度测试指令

$scope.cancel = function () {
             $('#pp_bsktexit').modal('show');
}; 
像这样的东西,我可以测试,它似乎不太:

var nextScreenPath='C_HIST'

$scope.goBack = function() {                
            //sessionService.save($scope.sessionData);              
            $location.path(nextScreenPath);
}
以及测试:

it('should return location path as nextScreenPath', function(){
            var nextScreenPath = 'C_HIST';
            expect($location.path()).toEqual('');
            scope.goBack();
            expect($location.path()).toEqual('/' + nextScreenPath);

});

但是我不能完全转移逻辑/知识来测试原始查询。有人有什么想法吗?我需要模拟一些东西吗?

因此,您似乎直接使用jQuery,这使得模拟有问题

您应该改为使用angular.element,如果jQuery存在,它将在后台自动使用jQuery

然后在测试指令中,您通常会使用spies:

间谍元素

有几种spyOn方法,用于返回固定值或调用假函数。请查看间谍的jasmine文档: