- In this blog entry I’m going to show you a test from my current test repository at involving the Http service and observables.
- Originally, I used the Angular Class Webpack starter project as a base for my current efforts, and hats off to that team for wrestling WebPack, TypeScript and Karma to the ground to give everyone a sample to work off of.
- Our method under test is:
We discussed this class in a previous blog post, as well as the service itself.
- Comments are inline, and you’ll note we start by injecting the and into the test using the function (which requires an array of classes to look up the injectables, then an arrow function to inject the instances from the injector):
This test works, and for a single result, and one where you don’t have to manually fail a test based on a failed response, it’s all you need.
- Here is the same test, but using a version of the keyword that allows you to pass or fail a test in a response asynchronously:
Since the first case is easier, I’d recommend you do anything with a single response the first way, and back yourself into this method.