javascript - How do I spy on methods called from one class that exist in another class using Jasmine? -
i have method
thissvc.asyncoperation: function(id) { return thatsvc.getbyid(id);
is possible create spy tell me if thatsvc.getbyid has been called, or design anti-pattern? afaik, spies can created on single object.
you can spy on whatever want, in jasmine tests make sure service:
var thissvc, thatsvc; beforeeach(inject(function(_thissvc_, _thatsvc_){ thissvc = _thissvc_; thatsvc = _thatsvc_; }); it('.asyncoperation should call thatsvc.getbyid', function(){ spyon(thatsvc, 'getbyid'); var id = 4; thissvc.asyncoperation(id); expect(thatsvc.getbyid).tohavebeencalledwith(id); })
Comments
Post a Comment