var testappserviceone = angular.module('testappserviceonemodule',[])
testappserviceone.factory('testappServiceone',[function(){
return function (x,y) {
function addobj (x,y){
return x+y;
}
return{
add:addobj
}
}
}]);
describe('testappserviceone add method functionality', function(){
beforeEach(function () {
spyOn(testappServiceone(10,15),'add').and.callThrough();
});
it('testappServiceone add method functionality', function() {
testappServiceone(10,15).add();
expect(testappServiceone(10,15).add).toHaveBeenCalled();
});
});
期待间谍,但得到了功能。
我认为spy()并没有创造间谍。请帮助我理解和解决这个问题。
答案 0 :(得分:0)
testappServiceone(10,15) // -> Object A
testappServiceone(10,15) // -> Object A'
// A !== A'
var foo = testappServiceone(10,15);
spyOn(foo, 'add');
foo.add()
expect(foo.add).toHaveBeenCalled()