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

Writing Specs for AppComponent

Let's write specs using Jasmine to test AppComponent:

  1. Create a app.component.spec.ts file to write specs or tests for AppComponent.
  1. Import modules such as async, ComponentFixture, TestBed, FormsModule, By, DebugElement, and AppComponent from Angular core.
  1. Write the following describe global function and declare the necessary variables:
     describe('AppComponent (templateUrl)', () => {
       let comp:    AppComponent; 
       let fixture: ComponentFixture<AppComponent>; 
       let de:      DebugElement; 
       let el:      HTMLElement; 
     });
  1. Then, create two beforeEach functions: one to compile the template and CSS, and the other to get the instance of the component. The code snippet is given here:
 // async beforeEach beforeEach(async(() => { ...

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