Tests are for sure one of the most important part or each developer work. In my opinion especially tests for Frontend part of an application, cause of fact that this is what end-user sees. So probably no-one wants to have someone to look for our mistakes, particularly if in the past we develop a feature properly, but someone (generally “future me” ;)) has changed something in very different place what impact an error.

That’s why I decided to spend awhile and prepare an article about a few problematic test cases which I met in the last few months working with Angular (v.9.0.x) and possibilities to solve it with Spectator (v.5.0.0).

Quick Guide

As first, a few words about Spectator. It is a tool that can make unit testing enjoyable! It allows keeping clean and streamlined unit tests without TestBed, and ComponentFixture, but furthermore allows testing components, directives and services and even more if only you need that. How to do this? Just:

$ npm install @ngneat/spectator — save-dev

For basic example of usage I will recommend becoming acquainted with very good documentation on GitHub, because below, I won’t describe basic constructions and usage cases, but some fancy cases you may find useful.