5. Add simple test

  • Delete the default tests made by the Angular CLI

**src/app/app.component.spec.ts

  • Add a describe block.

src/app/app.component.spec.ts
describe(`Component: App Component`, () => {

});
  • Add a it block.

src/app/app.component.spec.ts
describe(`Component: App Component`, () => {
  it('add 1+1 - PASS', () => {

  });
});
  • Add an expectation.

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

Run the test with Karma test runner

  • In the terminal at the path of the project start the unit tests with the following command

ng test

Figure: Karma output in terminal

Last updated