Angular Unit Testing
Intro to TestBed & Spectator

Testing Pyramid

What is unit test?

Unit tests form the base of the testing pyramid. They test individual components or functionalities to validate that it works as expected in isolated conditions. It is important to run a number of scenarios in unit tests – happy path, error handling, etc.

Unit testing pros and cons

  • Allow safer refactoring
  • A better understanding of the code
  • Force better code
  • Add new features without breaking anythink                 
  • Harder to add some changes
  • Time
  • Cannot catch all errors in a program                                                                                                   

Angular testing tools

  • Jasmine is a behavior-driven development framework
  • Karma is a task runner for our tests in the browser.
  • TestBed is the primary API for unit tests for Angular application
  • Spectator is a wrapper under TestBed to simplify Angular unit tests.

Angular testing example

Angular testing example

Jasmine 

TestBed 

Angular testing example

Angular testing example

Jasmine 

Spectaor

More info

Thanks for your attention

Angular Unit Testing. Intro to TestBed & Spectator

By TenantCloud

Angular Unit Testing. Intro to TestBed & Spectator

Basic info about unit testing in Angular with spectator

  • 151