Have you ever tried to use async pipes in your Angular application and wondered how to unit test them ? In this post we are going to explain how to unit test them in deeply nested smart components typically used in large scale Angular applications.
If you are looking to learn more about async pipes and how to use them with deeply nested smart components, have a look at the post "Angular OnPush Change Detection and Component Design - Avoid Common Pitfalls"
If you are looking to learn more about async pipes and how to use them with deeply nested smart components, have a look at the post "Angular OnPush Change Detection and Component Design - Avoid Common Pitfalls"
Data service
First, lets create a data service that sets up an rxjs observable and subject that we will use in the application
Front end
Next, lets create a front end page with the ability to fire immutable visibility changed and reset events, along with the ability to show content depending on the state of the async pipe.
Unit testing
Component Host
It is necessary to wrap the component in a host component to facilitate unit testing async pipes. Click the following github issue report to discover more information "Forcing change detection when unit testing onPush Components"
Unit Tests
The following code are three unit tests in BDD style
Source code
Refer to the following github page to fork the codebase and / or check it out to execute locally https://github.com/jamesioppolo/AsyncPipesUnitTesting
Comments
Post a Comment