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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -