我有一个名为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>
任何人都可以帮我解决这个问题吗?