Private method Unit testing with Jasmine
angularjs, jasmine, unit-testing
Solution
Thanks jabko87.
In addition, if you want to pass the the arguments use the below example:
const myPrivateSpy = spyOn<any>(service, 'transformNative').and.callThrough();
myPrivateSpy.call(service, {name: 'PR'});
Note: Here service is the Class, transformNative is the private method and {name: 'PR'} passing an object argument
Problem
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('productDisplay', function(){ var myPrivate = function(){ //do sth } this.doOfferCal = function(product, date){ //call myPrivate //do sth too return offer; } }); ``` Using jasmine it straightforward to code test for "doOfferCal" but I want to write unit test for myPrivate too. How can I do it? Thanks in advance.