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文档: