From the course: Angular: Testing and Debugging
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Testing components - Angular Tutorial
From the course: Angular: Testing and Debugging
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
-
-
-
-
-
-
-
(Locked)
Testing overview2m 26s
-
(Locked)
Basic Karma configuration3m 35s
-
Testing services5m 22s
-
(Locked)
Fixing injection dependency errors6m 1s
-
(Locked)
Testing pipes4m 29s
-
(Locked)
Testing components6m 27s
-
(Locked)
Challenge: Custom test bed wrapper22s
-
(Locked)
Solution: Custom test bed wrapper1m 53s
-
(Locked)
-
-
-