O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Angular components

We have just seen how to test a service in Angular application. Now, let's discuss testing an Angular component. Perform the following steps to create AppComponent for the application:

  1. Create a file named app.component.ts.
  1. Import modules such as Component, TodoService, and Todo that are necessary for the AppComponent, as shown:
        import { Component } from '@angular/core'; 
        import { Todo } from './todo'; 
        import { TodoService } from './todo.service'; 
  1. Define the AppComponent class, as demonstrated:
        export class AppComponent {} 
  1. Decorate the AppComponent class by the @Component attribute with the selector, providers and templateUrl metadata:
 @Component({ selector: 'my-app', templateUrl: './app.component.html', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required