Angular unit testing building blocks
The following are some of the key building blocks to be used when writing unit tests for Angular apps:
- TestBed: This is the most important building block of Angular testing utilities.- TestBedis used to create an Angular testing module using theÂ- @NgModuleclass, which is configured using theÂ- configureTestingModule method. Invoking- configureTestingModuleon- TestBedcreates a testing environment for the component to be tested. Essentially, the component to be tested is detached from its own module and reattached to the Angular testing module. A metadata object declaring the components to be tested is passed to theÂ- configureTestingModule method.Â
After configuring the test environment, the next step is to create a component fixture, which is done by invoking the createComponent API on TestBed. Once the createComponent API is invoked, TestBed can't be configured any further.
Note that the configureTestingModule and createComponent methods are invoked within...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                