7. Add another test to check a property

  • Remove the failing test

  • Under the last it block add another it block and write a test to check the title property is set correctly

src/app/app.component.spec.ts
import { AppComponent } from './app.component';
describe(`Component: App Component`, () => {
  it('add 1+1 - PASS', () => {
        expect(1 + 1).toEqual(2);

  });
  
  it(`title equals 'Angular Superpowers'`, () => {
    const component = new AppComponent();
    expect(component.title).toEqual('testing');
  });
});
  • set the title accordingly in the component

src/app/app.component.ts
export class AppComponent implements OnInit {
  title = 'testing';
  ...
}
  • Note that the AppComponent requires a CompanyService parameter. For now, we won't use it in the test though, so we just pass null.

  • Karma should still be running from your last test and on save of the spec file automatically re-run.

Last updated