'How to test an Angular method which calls service and gets values?

I am trying to test this method, I have tried spying but the coverage shows not covered. Basically what this method does is, it checks if there is data available to use. using if we call a service and using condition we get the value. after that what we do is use that data and modify it using other methods. for example: once we get the data in date format we try to format that date to show as January 1, 2022. Also a method to reverse the dates so that it shows the recent date first. here is the coverage that i want to cover: [coverage-report][1]

How to test the ngOnInit



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source