我有一个名为 clickElement 的指令:
function clickElement( $location) {
var clickElementDefinition = {
restrict: 'A',
scope: {
clickElement: "="
},
link: clickElementMethod
};
return clickElementDefinition ;
function clickElementMethod(scope, element, attrs) {
element.bind('click', function (event) {
if (scope.clickElement) {
var arr = scope.clickElement.split("?");
var queryParam = arr[1].split("=") || "";
$location.path(arr[0]).search(queryParam[0], queryParam[1]);
}
});
}
};
我如何对搜索方法进行单元测试?
我添加了 spyOn 路径方法:
spyOn($location, 'path').and.returnValue('/test/1');
expect($location.path).toHaveBeenCalledWith('/test/1');
expect($location.search).toHaveBeenCalled();
我收到一个错误:
Error: Expected a spy, but got Function.
at Object.<anonymous>
谁能帮我解决这个问题?