Private method Unit testing with Jasmine

前端 未结 5 1768
情深已故
情深已故 2021-02-04 01:40

I was coding test cases for an angular application using jasmine. But many internal methods are declared as private in the services.

Example:

App.service         


        
5条回答
  •  渐次进展
    2021-02-04 01:54

    Achan is 100% right, but if you really need to call private method in your tests (what should be never :-) ) you can do it by:

    var myPrivateSpy = spyOn(productDisplayService, "myPrivate").and.callThrough();
    myPrivateSpy.call();
    

提交回复
热议问题