From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Testing components

Testing components - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Testing components

- [Instructor] Let's create a unit test for our app component to confirm that it loads the correct title. The Angular CLI tool created a spec file for us when we created the project. Angular wants to make our lives easier, so it already imported TestBed and the AppComponent. It also made a few simple passing tests. This is a great starting point for real-world projects but for this video, let's pretend we're starting from scratch without Angular's help. I'm going to delete the content of his file so we can build our tests manually. Select all, delete. We need to import the class we want to test, as well as Angular's TestBed and ComponentFixture classes. I'll make a new import statement and import TestBed and ComponentFixture from @angular/core/testing. We use the TestBed class to configure our modules and resolve any dependencies our components might need. The ComponentFixture class gives us access to the component itself and its state. We're also going to need to import the class we…

Contents