Unit Testing in Angular

    Adam Morgan

Author of The Angular Tutorial

www.theangulartutorial.org

www.codecompanion.io

Code: https://github.com/atom-morgan/atlantajs-testing-in-angular

The Test Tooling Landscape

Karma

Jasmine

Protractor

Mocha

AVA

Chai

Cypress

Jest

Why test?

  • Verify our code behaves as we expect it to
  • Avoid software defects
  • Manual QA is expensive and time-consuming

How and what should I test?

4!

1!

2!

Testing Adder with Jasmine

Test specs read like plain English

  Testing a service

Implementing the service

This is why developers often refer to test cases and their expectations for how our code should behave as documentation, or a design aid, for their actual code.

  Testing a service with HTTP

  Testing a service (HTTP)

Implementing the service

Why mock?

Think of doing a "test run" of a restaurant

Front-end = waiters

Back-end = cooks

Mock to verify front-end can handle back-end responses

Testing a component

E2E Tests with Cypress

Thank you!

Unit Testing in Angular

By atom-morgan

Unit Testing in Angular

  • 352