[英]How do I assert that an inner function was called with jasmine?
我的應用程序中有一個帶有javascript的類樣式聲明,我需要測試是否調用了內部方法。
結構是這樣的...
angular.module("MyApp").factory('myClass', ['$rootScope', function (rootScope) {
function active(type) {
//how do I see if this method was called if cleartools public method is called?
}
return {
active: active,
clearActives: function() {
active('');
}
}
}]);
我如何查看如果調用clearActives()是否調用了active()函數?
您可以通過檢查調用方函數名稱來做到這一點,這將要求您命名函數
function active(type) {
var callerName = arguments.callee.caller.name;
if(callerName == "clearActives") {
//do something
}
}
return {
active: active,
//Names the function
clearActives: function clearActives() {
active('');
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.