{Front-end Unit Testing}

How to use Angular tooling to write unit tests in Jest

What Is Unit Test

A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work.

A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class, or multiple classes working together to achieve one single logical purpose that can be verified.

Unit Testing Steps

Mock

Isolate a piece of code from it's dependencies 

1.

2.

Act

Perform an action to set the system in certain state

3.

Assert

Compare result of code execution with desired result

A Good Unit Test...

  • Has full control over all the pieces running

  • Can be run in any order  if part of many other tests

  • Runs in isolated (no BE access, for example)

  • Consistently returns the same result

  • Tests a single logical concept in the system

Our Toolset

TestBed

Practice Time!

Tanks For attendance 

Sources:

Unit Testing KT

By Gleb Zhidkov

Unit Testing KT

  • 16