Private method Unit testing with Jasmine

前端 未结 5 1753
情深已故
情深已故 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:44

    To test inner functions I call the outer function that calls the inner function and then vary my input according to what the inner function requires. So, in your case you would call productDisplay and vary your input based upon what myPrivate needs and then verify that you have the expected output. You could also spy on myPrivate and test things that way using .havebeencalledwith or .andcallthrough.

提交回复
热议问题