Testing Effects: Testing the Error Case
Learn how to write unit testing code to handle the error case of the effects.
We'll cover the following...
Introduction
The ProductsEffects have been defined in such a way that when the loadProductsAction() is dispatched from our application, the loadProducts$ effect detects it by subscribing to the actions$ observable in lines 17–18. Then, in order to fetch the product data, our effects connect to the server in line 19. If the product data isn’t successfully returned from the server, we dispatch another action called getErrorAction in line 21. Let’s unit test this error case.
Let’s visualize the success case in the following illustration:
Unit testing the error case
We can unit test the error case by following the steps detailed below.
Defining the specs
Let’s use the it function to define the specs of our test in lines 62–64.
Executing the testScheduler
In the ProductsEffects, we’ve interacted asynchronously with the server to fetch the data via the ProductsService. To test this asynchronous behavior, let’s use the ...