Lesson 7

Introduction to Angular's TestBed

WARNING: This module is deprecated and no longer receives updates. Protractor is likely being removed as the default from Angular applications and Protractor itself will likely stop receiving updates and development in the future. I would recommend checking out the Test Driven Development with Cypress/Jest as a replacement.

Using TestBed to configure a testing environment


Lesson Outline

Introduction to Angular's TestBed

In previous lessons, we have talked about the concept of isolating our unit tests. If we are running tests on the SomePage component then we don't care about the rest of the application, in fact, we want the rest of the application completely out of the picture.

This is simple enough if we are just testing a simple object that can be instantiated in isolation, like this example of testing a provider:

import { MyProvider } from './my-provider';

describe('My Provider', () => {
  let myProvider;

  beforeEach(() => {
    myProvider = new MyProvider();

  it('should do something', () => {});

If the provider is simple enough, then we can structure our tests like this just fine. Angular applications aren't always so simple, and if we are relying on dependency injection or importing modules then things get a bit more complicated - we can no longer just do:


Thanks for checking out the preview of this lesson!

You do not have the appropriate membership to view the full lesson. If you would like full access to this module you can view membership options (or log in if you are already have an appropriate membership).