Creating a new file
Let's first create a new file, trello.service.spec.ts, in our services folder. All our test cases for the Trello service will be written in this file.
Our Trello service has only one function right now, that is, to fetch the boards from the JSON file using the HTTP GET method. We use promises here to fetch the response and return a success or a failed promise. If we look in our function, we have two code flows that would require testing: one to check if we already have boards in our public variable, and the second to make an HTTP call if we did not have the boards.
Again, there can be multiple unit tests that can be written for this class, but we will focus on two test cases: one to check if we do not have a board object ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access